Homework

  • Create an algorithm that uses selection and/or iteration that will represent one player’s turn in a game.

  • During a turn, each player gets 4 attempts/chances to get the greates number possible.

  • During each attempt the player will use a random number generator to select a random number 1-10.

  • After the player has had 4 chances, their score is the greatest number they receieved from the random number generator, and their turn is over.

Use the following flowchart to assist you:

#BASE VERSION
import random
attempts=0 
score=0 

while attempts <=4:
    random_number = random.randint(1, 10)
    temp_score=random_number
    if temp_score > score:
        score=temp_score
        attempts=attempts+1
        print(score)
    else:
        attempts=attempts+1
        print(score)
6
8
8
9
9
#EXTRA VERISION
max_attempts = 5
score = 0

print("COOL GAEM RIGHT HERE")
print(f"You have only{max_attempts} attempts so get a good score")

for attempts in range(1, max_attempts + 1):
    random_number = random.randint(1, 10)
    print(f"Attempt {attempts}: Random Number: {random_number}")
    
    if random_number > score:
        score = random_number
        print(f"New High Score: {score}")

print(f"Game Over! Your super dooper dopper final score is: {score}")

COOL GAEM RIGHT HERE
You have only5 attempts so get a good score
Attempt 1: Random Number: 8
New High Score: 8
Attempt 2: Random Number: 8
Attempt 3: Random Number: 9
New High Score: 9
Attempt 4: Random Number: 6
Attempt 5: Random Number: 3
Game Over! Your super dooper dopper final score is: 9