0

Simple Input/Output question (python beginner)

I want to run a program to understand a python intro lesson. the lesson proposes the following syntax: s = input("Enter something here") print(s) Something I get the first line printed because the only way I have to go to next line is by tapping the enter key on my phone. From then on, there's no way to run this program. please help.

2nd Apr 2017, 8:07 PM
Javier
Javier - avatar
17 Réponses
+ 8
oh, I believe you were using shell instead of IDLE.. when you open IDLE, you must press Ctrl+N to open a new window and write your code to execute. then, you copy you code, save it, and press F5 to run the module
3rd Apr 2017, 1:25 PM
LayB
LayB - avatar
+ 8
@Chris, semicolon in Python???
2nd Apr 2017, 10:03 PM
LayB
LayB - avatar
+ 8
@Javier, python doesn't use ; at the end of the statements. I'm not sure if I got your point, but to do anything with your variable and show the result you must use print statement. s = input("enter something here") print (s) if s == "something": print(yay!) else: print("oh no") what your 3rd line should do?
3rd Apr 2017, 10:08 AM
LayB
LayB - avatar
+ 8
when you use "input" statement, the program waits some entry from the user. the rest of the code will be executed only after this entry. So, when you press enter, your input is actually an empty string like ""
3rd Apr 2017, 11:52 AM
LayB
LayB - avatar
+ 8
well, you must press enter. it's the trigger to Python understand that you're done and will go to the next line
3rd Apr 2017, 12:27 PM
LayB
LayB - avatar
+ 8
name = input("your name") print (name) output: your name Javier you must create a variable and then store your input on it. then, you show your variable with its content
3rd Apr 2017, 7:43 PM
LayB
LayB - avatar
+ 8
I'll post your example on my code playground. take a look there and see if it's what you're looking for
3rd Apr 2017, 10:24 PM
LayB
LayB - avatar
+ 1
Thanks so much for helping me :) I should clarify the exercise works when following the exercise example. I'm trying to replicate on my comp. I changed to notepad++ from Python IDLE and I now have no issue going into next line by pressing enter :) I've typed the following: s = print("name:") print (s) My name now my challenge is how to run this. Hitting enter at the end doesn't yield anything :)
3rd Apr 2017, 1:02 PM
Javier
Javier - avatar
0
Thanks a lot Chris
2nd Apr 2017, 8:51 PM
Javier
Javier - avatar
0
@LayB, did not work... What should I do?
2nd Apr 2017, 10:13 PM
Javier
Javier - avatar
0
@LayB, the thing is that I can't go past line 1: 1 >>> s = input("enter something here"). For me to go to line 2, I don't know how to do so except by pressing enter on my keyboard after finishing the first line. This triggers the code in line one to be printed: 2 enter something here. If I press enter again, I go back to: 3 >>> So, I would just need to know how to be able to keep writing syntax from line 1 into line 2 without simply runing the code in line 1
3rd Apr 2017, 11:47 AM
Javier
Javier - avatar
0
I kind of figured something like that. Still, how to go into line 2 after input statement to keep correct syntax? I've tried \n, which yields an errror message. when you type an input statement and you finish it, how do you go into the next line for output?
3rd Apr 2017, 12:18 PM
Javier
Javier - avatar
0
sorry, correction: s = input("name:") print (s) My name
3rd Apr 2017, 1:09 PM
Javier
Javier - avatar
0
Thaaaanks :) so, I tried the following: input("your name: ") Javier Output is: your name: I get an error message: NameError, Javier is not a defined name
3rd Apr 2017, 7:42 PM
Javier
Javier - avatar
0
unfortunately I only get the input printed. the output yields error: unexpected EOF while parsing. Thanks so much. Don't worry, I'll look somewhere else also until I can get it done. Tried to upvote all your answers, but what do you know? I seem to get an error too with that!
3rd Apr 2017, 10:19 PM
Javier
Javier - avatar
0
Yes, it worked fine. It works when I try it on the sololearn question interface as well. it's on pc where the output doesn't seem to show for one reason or another.
3rd Apr 2017, 11:19 PM
Javier
Javier - avatar
- 1
When using input you have to remember to use a semicolon at the end. First line should look similar to this: s = input("Enter something");
2nd Apr 2017, 8:32 PM
Chris Crawford
Chris Crawford - avatar