Python Forum
I can't for the life of me get this basic If statement code to work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I can't for the life of me get this basic If statement code to work
#4
There are restrictions on code you can enter in the interpreter. You could enter your program like this:
[output]>>> x = 5
>>> if x < 10:
... print("smaller")
...
smaller
>>> if x > 20:
... print("bigger")
...
>>> print("finis")
finis
The python interpreter changes the prompt between ">>>" and "...". When the prompt is "...", python is telling you that it thinks you are inside an indented block of code, like the body of code following an "if" statement. Enter a blank line to exit the block and get the ">>>" prompt, then you can enter your second "if" statement. The interactive interpreter expects you to enter code one expression at a time.
Reply


Messages In This Thread
RE: I can't for the life of me get this basic If statement code to work - by deanhystad - May-21-2024, 03:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Information Is it possible to multi line a Basic Function Construct line statement? If so how? BrandonKastning 7 531 May-23-2024, 03:02 PM
Last Post: deanhystad
  hi need help to make this code work correctly atulkul1985 5 1,046 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 855 Oct-22-2023, 09:08 PM
Last Post: tronic72
Photo Python code: While loop with if statement HAMOUDA 1 712 Sep-18-2023, 11:18 AM
Last Post: deanhystad
  An unexplainable error in .format statement - but only in a larger piece of code? ToniE 4 870 Sep-05-2023, 12:50 PM
Last Post: ToniE
  Beginner: Code not work when longer list raiviscoding 2 986 May-19-2023, 11:19 AM
Last Post: deanhystad
  code won't advance to next statement MCL169 2 851 Apr-11-2023, 09:44 PM
Last Post: Larz60+
  Why doesn't this code work? What is wrong with path? Melcu54 7 2,135 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Code used to work 100%, now sometimes works! muzicman0 5 1,672 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  color code doesn't work harryvl 1 1,047 Dec-29-2022, 08:59 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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