I started coding today’s exercise from yesterday since we
focused mainly on debugging.
I am trying to become a good programmer by adding comments
to my code.
My Higher Lower Game Code:
# import modules
import random
import art
from game_data import data
score = 0
A = []
while True:
# print logo
print(art.logo)
# select 2 options from the game data
if A == []:
A = random.choice(data)
B = random.choice(data)
while B == A:
B = random.choice(data)
print(f"Compare A: {A['name']}, a {A['description']}, from {A['country']}.")
print(art.vs)
print(f"Against B: {B['name']}, a {B['description']}, from {B['country']}.")
# get user input
choice = input("Who has more followers? Type 'A' or 'B': ").upper()
if choice == "A":
chosen = A['follower_count']
not_chosen = B['follower_count']
chosen_data_set = A
elif choice == "B":
chosen = B['follower_count']
not_chosen = A['follower_count']
chosen_data_set = B
else:
print("Sorry, that was not a valid option.")
print("Try again.")
# compare user input to the data
if chosen > not_chosen:
# store number of wins
score += 1
print(f"You're right! Current score {score}")
A = chosen_data_set
else:
# if user input is wrong, end the game and print the final score
print(f"Sorry, that's wrong. Final score: {score}.")
break
:)
Comments
Post a Comment