Python 7 Levels, L2, Unit 13, if-else Statement

Powered By EmbedPress

Exercise 1:

score = int(input("Please input your score:"))
if score > 90:
    print("Excellent!")
    print("Please go to Admin Office for gift.")
else:
    print("Carry on!")
print("Achievement Test")

Exercise 2:

year = int(input("Please input a year:"))
if (year%4==0 and year%100!=0) or (year%400 == 0):
    print("Leap year.")
else:
    print("Ordinary year.")

Exercise 3:

import random
r = random.randint(1,5)
number = int(input("Please guess the random number between 1 and 5:"))
if number == r:
    print("Congratulations. You win. ^_^")
else:
    print("Sorry. You lose. -_-")

Homework:

import random
print("----Guess Odd Even Number Game----")
rand = random.randint(1,1000)
print("Computer generated a random number between 1 and 1000")
number = input("Please guess it's odd or even?(odd/even)")
if((rand%2 == 0 and number == "even")or(rand%2 != 0 and number == "odd")):
    print("The number generated by computer is ",rand,". Congratulations. You Win")
else:
    print("The number generated by computer is ",rand,". Sorry, You Lose.")

dahan1999

1 Comment

Leave a Reply

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

Related Posts