Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

# Simple IF statement

number = 10
if (number > 0):
print("This is a positive number")
elif (number == 0):
print("The number is zero - not positive or negative.")
else:
print("This is a negative number")

# More complicated IF statement


# Rules: If you are 21 or older, you are not young. If you earn 100,000 or more
you are rich.
age = int(22)
salary = int(100000)
if ((age < 21) and (salary >= 100000)):
print("You are young and rich!")
elif ((age >= 21) and (salary >= 100000)):
print("You are not young but you are rich")
elif ((age < 21) and (salary < 100000)):
print("You are young and but not rich")
elif ((age >= 21) and (salary < 100000)):
print("You are not young and not rich")
else:
print("We've tested every combination of age and salary - this code will never
be reached.")

# Simple loop. This prints: 0, 1, 2, 3, 4


number_of_loops = int(input("How many times would you like to loop? "))
for c in range(number_of_loops):
print ("Loop #" + str(c))

#Creating a module from your code

# Type modules at the top of your code.


def greeting():
print (" Hello out there!")
print (" This is a two line greeting.")
return #go back to the main program and continue on.

You might also like