Add lab 6

This commit is contained in:
sys_32
2023-10-05 16:35:25 -07:00
committed by GitHub
parent 9fdb25d8d5
commit 387de0f5e7
4 changed files with 122 additions and 0 deletions

38
lab6/ex1-if-else-lab2.py Normal file
View File

@@ -0,0 +1,38 @@
# Edwin Hui
# imports random module
import random
# sets the value of rps to a random number between 0-2
rps=random.randint(0,2)
# converts the random number to either R for rock, P for paper, or S for scissors
if rps == 0:
rps="R"
elif rps == 1:
rps="P"
else:
rps ="S"
# prompts the user to enter 0-2 to choose rock, paper, or scissors.
usrrps=int(input("Enter 0 for Rock, 1 for Paper, 2 for Scissors: "))
# converts user number to string
if usrrps == 0:
usrrps="R"
elif usrrps == 1:
usrrps="P"
else:
usrrps ="S"
# prints the computer choice
print("computer chose:", rps)
# prints the results
if usrrps == rps:
print("Tie")
elif usrrps == "R" and rps == "P":
print("You lose")
elif usrrps == "R" and rps == "S":
print("You win")
elif usrrps == "P" and rps == "R":
print("You win")
elif usrrps == "P" and rps == "S":
print("You lose")
elif usrrps == "S" and rps == "R":
print("You lose")
elif usrrps == "S" and rps == "P":
print("You win")

20
lab6/ex2-if-else-lab2.py Normal file
View File

@@ -0,0 +1,20 @@
# Edwin Hui
# Prints a list of animals that are avalible to be chosen.
print("Octopus, Fish, Tarantula, Snake")
# Asks the user to choose one of the animals listed.
userchoice=input("Please enter one of the animals listed: ")
print("the program will now guess your animal")
# Program asks the susers questions to determine what animal they chose.
choice1=input("Does your animal live in the ocean? (Y/N)")
if choice1=="Y":
choice2=input("Does your animal have 8 legs? (Y/N)")
if choice2=="Y":
print("Your animal is an Octopus")
else:
print("Your animal is a Fish")
else:
choice3=input("Does your animal have 8 legs? (Y/N)")
if choice3=="Y":
print("Your animal is a Tarantula")
else:
print("Your animal is a Snake")

30
lab6/ex3-if-else-lab2.py Normal file
View File

@@ -0,0 +1,30 @@
# Edwin Hui
# import the random module
import random
# generate a random number between 1-10
secretNum = random.randint(1,10)
# Prompt the user to guess the number picked by the random module
print("The program has generated a random number between 1-10")
print("guess the number within 4 tries and you win.")
print("If you dont you lose!")
# sets the value of attempts var to 4
attempts = 4
# runs a while loop that will run until the attempts var is 0
while attempts > 0:
guess = int(input("Enter your guess: "))
# if the guess is equal to the secret number the user wins
if guess == secretNum:
print("You win!")
break
# if the guess is higher than the number the user is told that and a attempt is removed
elif guess > secretNum:
print("Number too high!")
attempts -= 1
# if the guess is lower than the number the user is told that and a attempt is removed
elif guess < secretNum:
print("Number too low!")
attempts -= 1
if attempts == 0:
# if the attempts var is 0 the user loses and the number is printed
print("You lose!, the number was:", secretNum)
break

34
lab6/ex4-if-else-lab2.py Normal file
View File

@@ -0,0 +1,34 @@
# Edwin Hui
# asks the user to pick a shape from a image
print("Pick a shape contained in this image: https://csns.cysun.org/download?fileId=7899012")
# asks the user questions to determine what shape they chose
red=input("is the shape red? (Y/N):")
if red == "Y":
border=input("is does the shape have a border? (Y/N):")
if border == "Y":
circle=input("is does the shape have a circle arround it? (Y/N):")
if circle == "Y":
print("Your shape is shape 5.")
else:
print("Your shape is shape 7.")
else:
circle=input("is does the shape have a circle arround it? (Y/N):")
if circle == "Y":
print("Your shape is shape 4.")
else:
print("Your shape is shape 2.")
# whether the user responds yes or no the same set of questions are asked, with different outcomes.
else:
border=input("is does the shape have a border? (Y/N):")
if border == "Y":
circle=input("is does the shape have a circle arround it? (Y/N):")
if circle == "Y":
print("Your shape is shape 8.")
else:
print("Your shape is shape 6.")
else:
circle=input("is does the shape have a circle arround it? (Y/N):")
if circle == "Y":
print("Your shape is shape 1.")
else:
print("Your shape is shape 3.")