Guest User

Untitled

a guest
Jun 10th, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. from art import logo
  2. from art import vs
  3. from game_data import data
  4. import random
  5. import os
  6.  
  7. def pick_a_person():
  8.     """Picks a random person from data list containing dictionaries with sets of persons and their attributes"""
  9.     return random.choice(data)
  10.  
  11. def who_has_more(person_a, person_b):
  12.     """Determines whom from the A&B pair has more followers and returns a string with an answer"""
  13.     if person_a['follower_count'] > person_b['follower_count']:
  14.         return "a"
  15.     else:
  16.         return "b"
  17.  
  18.  
  19. def add_score(score):
  20.     """Takes current score and adds one more point"""
  21.     return score + 1
  22.  
  23.  
  24. def clear_screen():
  25.     os.system('cls')
  26.  
  27.  
  28. def play_game():
  29.     person_a = pick_a_person()
  30.     answer = ""
  31.     score = 0
  32.     is_game_over = False
  33.  
  34.     while not is_game_over:
  35.         person_b = pick_a_person()
  36.         while person_b == person_a:
  37.             person_b = pick_a_person()
  38.         print(logo)
  39.         if score >= 1:
  40.             print(f"You are right! Current score: {score}.")
  41.  
  42.         print(f"Compare A: {person_a['follower_count']} {person_a['name']}, a {person_a['description']}, from {person_a['country']}.")
  43.         print(vs)
  44.         print(f"Compare B: {person_b['follower_count']} {person_b['name']}, a {person_b['description']}, from {person_b['country']}.")
  45.         guess = str(input("Who has more followers? Type 'A' or 'B': ")).lower()
  46.         answer = who_has_more(person_a, person_b)
  47.  
  48.         if guess == answer:
  49.             clear_screen()
  50.             score = add_score(score)
  51.             person_a = person_b
  52.         else:
  53.             clear_screen()
  54.             print(logo)
  55.             print(f"Sorry, that's wrong. Final score: {score}.")
  56.             is_game_over = True
  57.  
  58. play_game()
Advertisement
Add Comment
Please, Sign In to add comment