This question already has answers here:
How do I use raw_input in Python 3?
(9 answers)
Closed 3 years ago.
Is there any way of getting string input from user, other than raw-input, as that generates an error in my python program?
choice = raw_input("Do you want to convert from celcius to farenheit?")
NameError: name 'raw_input' is not defined
raw_input is not working because you are using Python 3. If you want raw_input, try downgrading to use Python 2 instead.
Alternatively, if you must use Python 3, you can use the function input like so:
name = input("Enter your name: ")
Related
This question already has answers here:
How do I use raw_input in Python 3?
(9 answers)
SyntaxError: multiple statements found while compiling a single statement
(6 answers)
Closed 2 years ago.
x=int(raw_input("Enter first number"))
y=int(raw_input("Enter second number"))
I do not understand why I am unable to post this into my Python 3.8.2 shell? Does anyone have any advice on an alternative way?
Thanks.
raw_input is python2 syntax and you should use.input.
it was renamed in python 3, refer to the following link:
http://docs.python.org/dev/py3k/whatsnew/3.0.html
change to:
x=int(input("Enter first number"))
y=int(input("Enter second number"))
Regarding the issue of pasting both in the terminal, you should read about the input function and you'll see that once it's called it waits for an input and is something was pasted it will take it as an input.
This question already has answers here:
How do I use raw_input in Python 3?
(9 answers)
NameError: name 'raw_input' is not defined [duplicate]
(1 answer)
Closed 3 years ago.
hae....my program keeps showing name 'raw_input' is not defined whenever i use a raw_input.
i.e
input1 = raw_input('Enter your number ')
then the error name 'raw_input' is not defined pops up...please help fix this.
thnks
Use input('Enter your number ') instead.
raw_input() is Python 2.x syntax.
raw_input() was renamed to input()
From What’s New In Python 3.0.
This question already has answers here:
Python 2.7 getting user input and manipulating as string without quotations
(8 answers)
Closed 4 years ago.
I am using the syntax
name = input(' Enter name: ')
print("hello " + name)
but every time I try to use a string with the name variable in it it says "name is undefined".
In Python 2.x, input tries to evaluate the input as a Python expression. You want to use the raw_input function instead:
# input('...') is equivalent to eval(raw_input('...'))
name = raw_input(' Enter name: ')
However, if you are just starting out, you should be using Python 3, where the input function behaves like Python 2's raw_input function. (There is no function that automatically tries to evaluate the string; it was considered a bad design choice to provide such a function.)
Python 2, use raw_input:
name = raw_input(' Enter name: ')
Python 2's input function is basically Python 3's eval(input(..))
Python 3, python 2's input is removed,
Only keeping raw_input which is renamed to input
This question already has answers here:
input() error - NameError: name '...' is not defined
(15 answers)
Closed 4 years ago.
After running the below code, python prompt error and tell me name "tony" is not defined.
print('Hello Sam, this is Javis')
#let user enter their name, "nm" being the variable
nm = input('Please tell me your name => ')
print('It is definitely nice to meet you',nm,'!')
I input name as "Tony"
What did i do wrong?
You need to use "+" Instead of commas since you're adding the input. like so:
print('It is definitely nice to meet you '+nm+'!')
This question already has answers here:
sscanf in Python
(9 answers)
How do I read from stdin?
(25 answers)
Closed 16 days ago.
I am trying to solve problems from SPOJ. I need to be able to read input from stdin for that, I did a lot of problems in C using scanf but wanted to try Python as well. How do i read the stdin inputs in Python? (wanna use Python 2.6/2.7)
In Python 2.7
To get integers or floats as inputs you can use the key word 'input'
Example: temp=input("Give your value")
Here temp only takes a float or int
There is another command raw_input() any value that raw input is given it converts it to string and assigns the value
Example:temp=raw_input("Give your value")
Here temp is of string type
For what I researched, in python 2.7(in all versions of python 2) the command of input is: raw_input( )
in this link have a tutorial about this:
https://linuxconfig.org/how-to-obtain-an-user-input-with-python-raw-input-function-example