Python AttributeError: 'NoneType' [closed] - python

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.

Related

use variables in dict python 3 [closed]

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}

Why is my code raising a TypeError exception? [closed]

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 7 years ago.
Improve this question
When I run the following code:
while start == "yes":
player1name = input("Player 1 what shall your character be called?")
player2name = input("Player 2 what shall your character be called?")
player1strength=print("Player 1,your strength score is :)", random.randint(1,7))
player2strength=print("Player 2,your strength score is :)", random.randint(1,7))
strengthdifference =(int(player1strength) - int(player2strength))
if strengthdifference<0:
strengthdifference=player2strength-player1strength
strengthdifference=strengthdifference/5
player1skill=int(input("Player 1,enter your skill score :)"))
player2skill=int(input("Player 2,enter your skill score :)"))
skilldifference=player1skill-player2skill
I'm getting this traceback:
File "C:\Computing\A453 Assessment\Task 3\main.py", line 18, in <module>
strengthdifference =(int(player1strength) - int(player2strength))
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
What am I doing wrong? How can I fix the error?
The error says their player1strength or player2strength (or possibly both) are None, which int() can't take as a parameter. It probably is both, since you are assigning the result of a call to print to each.
Maybe it does say something about *strength difference`, but since you haven't provided details, I can't respond to that.

String conversion error when reading user input [closed]

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()

Make print come after `if` in python [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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
Closed 9 years ago.
Improve this question
So I'm making a quiz and when I make an if statement in python to put a question I have to put the print before it(which I'm using at answers). So my question is how to make it come after without stopping the if statement. Any ideas appreciated. Sorry if its hard to know what I'm trying to say I'm a little new to python.
Something like this maybe?
answer = input ('Who was the last king of Rome? ') #use raw_input for python2.x
if answer == 'Tarquinius': print ('correct')
else: print ('incorrect')
print 'asdf' if 1 == 2 else 'fdsa'
Or if you don't get that this does, try this:
print "ok..nice" if raw_input("how are you ") == "ok" else "well, that's too bad"
Apparently people don't know the new inline if syntax, and think i'm trolling.
This should all be written in 1 line and does not require splitting.

I have variable which asks for users input, how can i print that variable also using if/else in python? [closed]

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"

Categories

Resources