<
Jun Day 3
>
Whiteboard Images
Plan
Warmup 1
Warmup 2
Warmup 3
Number Guessing Game Original Board
Number Guessing Game Secondary Board
Extended Number Guessing Game
Code Sections
Count odd numbers
Version 1
count = 1
limit = 1000
while(count < limit):
print(count)
count = count + 2
Version 2
count = 0
limit = 1000
while(count < limit):
if(count % 2 == 1):
print(count)
count = count + 1
FizzBuzz Warmup
count = 1
while count < 31:
if(count % 3 == 0):
print("Fizz", end="")
if(count % 5 == 0):
print("Buzz", end="")
if(count % 3 != 0 and count % 5 != 0):
print(count, end="")
print()
count += 1
Number Guessing Game
import random
guesses = 0
limit = 10
computer = random.randint(1, 100)
while(guesses < limit):
user = input("Enter a number: ")
user = int(user)
if(user > computer):
print("Your number is too high!")
elif(user < computer):
print("Your number is too low!")
else:
print("Your number is correct!")
break
guesses = guesses + 1
Extended Number Guessing Game
from random import randint
maximum = 1000
best_game_val = 0
best_count = 1000
game_count = 0
while(True):
cpu = randint(1, maximum)
count = 1
user = int(input("Enter a guess: "))
while(user != cpu):
count += 1
if(user > cpu):
print("Your guess is too high")
elif(user < cpu):
print("Your guess is too low")
else:
print("You got it!")
break
user = int(input("Enter a guess: "))
print(f"You got it in {count} guesses")
game_count += 1
if(count < best_count):
best_count = count
best_game_val = cpu
play_again = input("Would you like to play again? [y] for yes, [n] for no, [q] to quit: ")
if(play_again == 'y'):
continue
elif(play_again == 'n'):
break
elif(play_again == 'q'):
break
else:
print("Didn't get that, playing again.")
continue
print(f"Games played: {game_count}\nBest Game: {best_count} guesses, finding {best_game_val}")