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.")
[…] |____Unit 10 if statement| |____Unit 11 Logical Operators| |____Unit 12 Priority of Operators| |____Unit 13 if else statement| |____Unit 14 Multiple if Statements| |____Unit 15 Nested if Statements| |____Unit 16 Practice| […]