11
u/Sigg3net Aug 11 '20 edited Aug 11 '20
I use fstrings, personally:
print(f"Hello, {x}!")I would also specify a shebang:
#!/usr/bin/env python3at the top of the file, to let the shell know what to do.
On a side note, this belongs in /r/learnpython IMO. You're writing python, not shell script like BASH or sh. There's no input() in BASH.
-1
u/Fearless_Process Aug 11 '20
He's not writing shell script, he just cat'd the python code to the terminal.
2
Aug 11 '20
You still put the shebang at the top of .py files.
8
u/Fearless_Process Aug 11 '20
Yes but you don't have to if you point the python interpreter at the script. Only if you want to run the script directly
10
Aug 11 '20
You're running in python2, you need to do raw_input() instead. If you switch to python3 it will work as you intend it to. More info on why this is can be found here: https://stackoverflow.com/a/21122817
6
u/Buhsketty Aug 11 '20
Can you try python3 input.py
-28
u/LinkifyBot Aug 11 '20
I found links in your comment that were not hyperlinked:
I did the honors for you.
delete | information | <3
16
1
u/TurnoLox Aug 11 '20
Hi guys! I want to ask for help. In python, my "input()" doesn't work on my text editor. I tried executing the code above but as you can see, after I enter my name the system error appeared.
Another thing, In shell scripting. I tried the range operator "{}" in my text editor but it won't execute properly, in my terminal it works fine but if it is from a file then executing it, it won't work. For example, i type in my text editor {1..5} then executed that file in my terminal. It's output is {1..5} which is the exact same thing instead of listing the number from 1 to 5.
Ps. I tried using other text editor but it is still the same. The text editor won't recognize "()" "{}" as operators
8
Aug 11 '20
Your editor and your terminal are using different versions of python. Editor is probably using python3 and terminal python2.
1
u/ocket8888 Aug 12 '20
Idk what you expect
{1..5}to do. I don't think that's real Python. Maybe you wantrange(1, 6)?
1
0
u/Fearless_Process Aug 11 '20
It should be
x = str(input())This should fix it!
If that doesn't work I'm not sure, I tested it on my computer and it works... Are you using python3?
2
u/-m4x- Aug 12 '20 edited Aug 12 '20
To check what version of Python you are using in your terminal :
It should be a python 3 version.
If not, use :