Joseph Haugh
University of New Mexico
x = 5 # x is 5
y = 6 + 3 # y is 9
z = y * 2 # z is 18
x = 5
if x > 5: # If x is greater than 5
# Then do these statements
print("Greater than 5")
elif x == 5: # Else if x is equal to 5
# Then do these statements
print("Equal to 5")
else:
# Else do these statements
print("Less than 5")
i = 0
while i < 5: # Loop until i is NOT less than 5
# While the condition holds do these statements
print(i)
i = i + 1
# Then check the condition again and repeat if necessary
x = 5
y = 6
if x < 5:
x = 7 # This line is inside the if
y = 8 # This line is not
print(x) # Prints 5
print(y) # Prints 8
x = 0
y = 0
while x < 10:
x += 1 # This line is in the while loop
print(x) # And so is this one
print(y) # But this is not
# Read an int from user input
x = int(input())
# Now you can use the number
if x >= 0:
print("Positive")
else:
print("Negative")
Comments