Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie help with input
#6
You should get some basics sorted out and then you are good to go.

By referring to 'terminal' you actually use Python interactive interpreter. It interprets code row by row - you enter row, it interprets it (takes some action) and only after that it interprets next line.

If you paste two rows into interactive interpreter following happens: it reads firs row v = input("Enter value: ". Based on interpreting this line it displays input prompt and waits for action. After that it takes second line and it will become the action interpreter waited (i.e. entered value).

Interpreter don't execute row immediately only if row ends with :, it indicates that there will be code block which must be interpreted together (loops, functions, classes etc).

So some advices:

- don't paste your code into interpreter, type it (especially if you are a beginner)
- interpreter is for checking stuff (built-in help) and playing with ideas
- for code to 'run' you create file (with .py extension) and run it. For that you should use decent editor (my personal suggestion is VS Code).
- you can use interactive mode while running file.

Example:

Write following code into file (and save it as sample.py).

v = input('Enter the value: ')
print(v)
Then head to terminal and cd yourself into directory where your file resides. There enter python -i sample.py and your code runs as expected. However, after finishing (printing out value of v) it will remain active so that you can further test and play with your code in interactive interpreter. If you don't need interactivity you just omit -i.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Newbie help with input - by LouK - Aug-28-2019, 09:10 PM
RE: Newbie help with input - by jefsummers - Aug-28-2019, 10:16 PM
RE: Newbie help with input - by Yoriz - Aug-28-2019, 10:21 PM
RE: Newbie help with input - by Malt - Aug-29-2019, 05:59 AM
RE: Newbie help with input - by LouK - Aug-29-2019, 02:00 PM
RE: Newbie help with input - by perfringo - Aug-29-2019, 03:34 PM
RE: Newbie help with input - by LouK - Aug-29-2019, 05:38 PM
RE: Newbie help with input - by LouK - Aug-29-2019, 06:50 PM
RE: Newbie help with input - by LouK - Aug-29-2019, 08:41 PM
RE: Newbie help with input - by onlydibs - Dec-22-2019, 04:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Big Grin Newbie to Python - input and branching issue Sherine 3 3,186 Jul-31-2021, 01:09 AM
Last Post: Pedroski55
  Newbie ? Python 3 Input() jlgrunr 1 2,947 Feb-17-2018, 10:26 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020