Python 7 Levels, L2, Unit 15, Nested if Statements

Powered By EmbedPress

Exercise 1:

gender = input("Please input your gender")
if gender == "female":
    age = int(input("Please input your age:"))
    if age >= 9 and age <= 12:
        print("You can join.")
    else:
        print("Requirements not met.")
else:
    print("Requirements not met.")

Exercise 2:

c = int(input("Please input your French score:"))
m = int(input("Please input your Math score"))
e = int(input("Please input your English score"))
if (c + m + e) >= 280:
    print("Excellent!")
    print("Please go to Admin Office for gift.")
elif (c + m + e) < 260:
    print("Carry on.")
else:
    s = int(input("Please input your gym score:"))
    if s >= 90:
        print("Excellent!")
        print("Please go to Admin Office for gift.")
    else:
        print("Carry on.")

Homework:

import random
print("----Guess Odd Even Number Game----")
start=input("Will you start the game right away?(yes/no)")
if start == 'yes':
    rand = random.randint(1,100)
    print("Computer generated a random number between 0 and 100.")
    number = input("Please guess it is odd or even?(odd/even)")
    if((rand%2 == 0 and number == "even") or (rand%2 != 0 and number == "odd")):
        print("The generated number is ",rand,"Congratulations. You Win.")
    else:
        print("The generated number is ",rand,"Sorry. You Lose.")
else:
    print("Game quit.")

dahan1999

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts