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.)
Related
This question already has answers here:
f-strings vs str.format()
(5 answers)
Closed 2 years ago.
So i've tried the formats string methods in python but what are the differences between them? Which method is best for me?
example1:
name = 'Dash'
print(f'Hello {name}!')
example2:
name = 'Dash'
print('Hello {}!'.format(name))
Effectively both do the same thing.
The f you mention is an f-string which is available from python 3.6
Print f is just a newer and easier way of inserting a variable into a string. I think it came in in python 3.6 . Both do really the same thing
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:
What's the difference between `raw_input()` and `input()` in Python 3? [duplicate]
(6 answers)
Closed 3 years ago.
I wrote s small script to iterate through a dictionary in python3 that works just fine. I was working in a different machine that only had python2.4 installed. I copied the script and ran and now the code is not entering the if-statement within the for loop. I am assuming this is just a version discrepancy.
I had tried to look online to see what some differences could be between versions. Closest I have come to is 'dict.iterkeys()'
tests = {'1':'test1','2':'test2'}
answer = input('which test? ')
for test in tests:
if test == answer:
print(tests[test])
The expected output is for the tests I want to be printed. However, in python version 2.4 it is not entering the if-statement at all. In python3 this script works just fine.
Any insight helps.
Thanks!
Python3 replaced the old input statement with the functionality of python 2’s raw_input. It used to evaluate the input now it’s passed as a string for safety.
Replace the line: (py3)
answer = input('which test? ')
With: (py2)
answer = raw_input('which test? ')
Or:
answer = str(input('which test? '))
Refer to PEP3111 for more details.
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: ")
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