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
#3
(May-21-2024, 02:48 PM)deanhystad Wrote: The next line after an "if" must be indented one level. Not doing so is a syntax error.

You normally don't type code like this in python. Normally you write code to a file and pass the filename as an argument to python.

myscript.py
x = 5
if x < 10:
    print("Smaller")  # Must indent + 1 level
if x > 20:    # Must indent -1 level
    print("Bigger")
print("finis")

Hiya, thanks for the reply,

Sorry, I had indented after the ifs, but it didn't show up that way when I pasted it into here. Unfortunately, the issue is persisting though, I tried using your code in Python, and as the attached screenshot shows, exact same issue is still ocurring.

Attached Files

Thumbnail(s)
   
Reply


Messages In This Thread
RE: I can't for the life of me get this basic If statement code to work - by CandleType1a - May-21-2024, 02:56 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