Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I get the following error
ValueError: could not convert string to float: 'asdf\n'
from this code:
import sys
print('Hello, this is a short quiz. Please tell me your name')
name = int(sys.stdin.readline())
print('Are you ready %s?' % (name))
Unless your name is "7", that code is guaranteed to fail. You are casting the input string to an int. Try:
name = sys.stdin.readline().strip()
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I'm trying to have a user input an integer, while trying to catch errors if they put in floaters or strings. Any help would be awesome guys!!
try:
user_input = int(input())
except ValueError:
print("Please enter a whole number with no decimal points")
except NameError:
print("user_input not defined")
NameError is called when you try to access a variable not declared yet. But in this code, you will always create user_input, so the try block can't go to the nameerror block.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I want, use variables in dict, how can I?
ex:
field_one= input("Please Enter Field Name? ==> ")
field_two= input("Please Enter Field Name? ==> ")
fields_data = dict(field_one=data_one, field_two=data_two)
print (fields_data)
my problem is, the output not show user input, just show:
'field_one' = 'data_one'
'field_two' = 'data_two'
Use a dict literal:
fields_data = {field_one: data_one, field_two: data_two}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am doing some code for a flash Card quiz, however when I am running the program it says TypeError: 'NoneType' object is not callable in this line:
letter = print("Enter letter of your choice (A B C): ").upper()
print is used for printing text, not for text inputs.
To make a text input, use input (or raw_input if you use Python 2):
letter = input("Enter letter of your choice (A B C): ").upper()
I think your try to assign the output of 'print' to a variable causes the error.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
Can someone please explain how this works? Like, how does it count?
for a in range(2,5):
for b in range(1,2):
print (a+b,end=" ")
print("---",end=" ")
the output is: 3 --- 4 --- 5 ---
It just adds 2, 3, 4 with 1 and prints the result.
In Python-3.x, print() is a function and the argument end in it means
string appended after the last value, default a newline
Values returned by range(x, y) are [x, y-1]
If you don't know the usage of a function, you could open ipython and type something like the following:
help(print)
help(range)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
This is my code:-
print "Welcome to the English to Pig Latin translator!"
original = raw_input("Write a word")
if len(original)>0:
print origninal
else:
print "empty"
so here original is my variable. i get the string "empty" if user inputs no words, but if user inputs any words which is more than 0 characters (as defined in if statement) i am getting an error saying "name original is not defined".
I want the console to print the users input. What is wrong in my code?
There is a typo in your code. origninal should be original
if len(original) > 0:
print original
else:
print "empty"