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.
Related
This question already has answers here:
How do I execute a string containing Python code in Python?
(14 answers)
Closed 2 years ago.
I have a string 'user = input("Hello World")'. How can I execute the string to be able to run as a python command?
I am a new to python so I must have missed the basic syntax. please help me instead of routing me to another answer
You can use either of two exec or eval to run the string as python command based on your desired syntax or result
eval('user = input("Hello World")')
exec('user = input("Hello World")')
Visit exec and eval to learn more about them
This question already has answers here:
What's the difference between `raw_input()` and `input()` in Python 3? [duplicate]
(6 answers)
Closed 5 years ago.
Are raw_input and input the same? Because when I am coding in python I cannot use raw_input it takes up some error.
In Python 2, raw_input() is used for input. Whereas in Python 3.x, you have input().
Maybe your python version is 3.x.
From http://docs.python.org/dev/py3k/whatsnew/3.0.html
As this answer to this question mentions
the difference is that raw_input() does not exist in Python 3.x, while input() does. Actually, the old raw_input() has been renamed to input(), and the old input() is gone, but can easily be simulated by using eval(input()). (Remember that eval() is evil, so if try to use safer ways of parsing your input if possible.)
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
This question already has answers here:
Asking the user for input until they give a valid response
(22 answers)
Closed 8 years ago.
I have a program that gets a string from a user (raw_input) and sees if the length of it is greater than 8, for example. If it isn't it starts again, otherwise the program ends.
I'm using Python 2.7.8 and this is the code I'm using so far, but it doesn't work...
password = raw_input("Type in a password: ")
if password.len() > 8 :
print "Successful!"
else :
goto(1)
Can anyone solve this problem?
You need to learn the basics. You should start with a Python tutorial.
Here's the official Python tutorial from python.org; this section introduces the while statement, which you can use to make a loop.
https://docs.python.org/2/tutorial/introduction.html#first-steps-towards-programming
This question already has answers here:
Syntax error on print with Python 3 [duplicate]
(3 answers)
Closed 9 years ago.
I am a amature in Python,using the python33 version.The problem i am facing while i want to get output of a list of dictionary just like that.
dict = {'name':'Tanvir','Position':'Programmer'};
print dict['name'];
if i run the code then there showing a syntax error.same thing is happening for the list also.
Please help me to fix the problem.
Thanks in advance.
In Python 3, print is a function, so you need print(dict[name]). You also don't need the semicolons. You also need to read the Python tutorial to learn the basics first.