Python 7 Levels, L2, Unit 16, Practice

Powered By EmbedPress

Exercise 1:

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.")

Exercise 2:

import random
rand = random.randint(1,3)
if rand == 1:
    print("Enemy shows up left.")
elif rand == 2:
    print("Enemy shows up front.")
else:
    print("Enemy shows up right.")
direction = input("Please input direction of shooting:")
if (rand == 1 and direction == "a") or (rand == 2 and direction =="w") or (rand == 3 and direction == "d"):
    print("Bingo. You hit enemy.")
else:
    print("You missed.")

Homework:

import random
print("-----Rock Scissor Paper-----")
number = int(input("Please pick: (1.Rock 2.Scissor 3.Paper)"))
rand = random.randint(1,3)#random number from computer
person = "User's input"
computer = "Computer's input"
if number == 1:
    person = "Rock"
elif number == 2:
    person = "Scissor"
else:
    person = "Paper"

if rand == 1:
    computer = "Rock"
elif rand == 2:
    computer = "Scissor"
else:
    computer = "Paper"
if number == rand:
    print("Your input is: ",person,"Computer's input is: ",computer,"Tie. =_=")
elif (number == 1 and rand == 2) or (number == 2 and rand == 3) or (number == 3 and rand == 1):
    print("Your input is: ",person,"Computer's input is: ",computer,"You win. ^_^")
else:
    print("Your input is: ",person,"Computer's input is: ",computer,"You lose. ^_^")

dahan1999

1 Comment

Leave a Reply

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

Related Posts