how to make the higher or lower using python

Solutions on MaxInterview for how to make the higher or lower using python by the best coders in the world

showing results for - "how to make the higher or lower using python"
Cavan
07 Oct 2018
1from opponents import data
2import random
3from logos import logo, VS
4import os
5
6def get_random_account():
7  """Get data from random account"""
8  return random.choice(data)
9
10def format_data(account):
11  """Format account into printable format: name, description and country"""
12  name = account["name"]
13  description = account["description"]
14  country = account["country"]
15  # print(f'{name}: {account["follower_count"]}')
16  return f"{name}, a {description}, from {country}"
17
18def check_answer(guess, a_followers, b_followers):
19  """Checks followers against user's guess 
20  and returns True if they got it right.
21  Or False if they got it wrong.""" 
22  if a_followers > b_followers:
23    return guess == "a"
24  else:
25    return guess == "b"
26
27
28def game():
29  print(logo)
30  score = 0
31  game_should_continue = True
32  account_a = get_random_account()
33  account_b = get_random_account()
34
35  while game_should_continue:
36    account_a = account_b
37    account_b = get_random_account()
38
39    while account_a == account_b:
40      account_b = get_random_account()
41
42    print(f"Compare A: {format_data(account_a)}.")
43    print(VS)
44    print(f"Against B: {format_data(account_b)}.")
45    
46    guess = input("Who has more followers? Type 'A' or 'B': ").lower()
47    a_follower_count = account_a["follower_count"]
48    b_follower_count = account_b["follower_count"]
49    is_correct = check_answer(guess, a_follower_count, b_follower_count)
50
51    os.system("cls")
52    print(logo)
53    if is_correct:
54      score += 1
55      print(f"You're right! Current score: {score}.")
56    else:
57      game_should_continue = False
58      print(f"Sorry, that's wrong. Final score: {score}")
59
60game()
61
Lilly
17 Jan 2020
1logo = '''                                                                                                
2        ,--,                                                                                    
3      ,--.'|                     ,---,                                                          
4   ,--,  | :  ,--,             ,--.' |                                                          
5,---.'|  : ',--.'|             |  |  :                __  ,-.           ,---.    __  ,-.        
6|   | : _' ||  |,     ,----._,.:  :  :              ,' ,'/ /|          '   ,'\ ,' ,'/ /|        
7:   : |.'  |`--'_    /   /  ' /:  |  |,--.   ,---.  '  | |' |         /   /   |'  | |' |        
8|   ' '  ; :,' ,'|  |   :     ||  :  '   |  /     \ |  |   ,'        .   ; ,. :|  |   ,'        
9'   |  .'. |'  | |  |   | .\  .|  |   /' : /    /  |'  :  /          '   | |: :'  :  /          
10|   | :  | '|  | :  .   ; ';  |'  :  | | |.    ' / ||  | '           '   | .; :|  | '           
11'   : |  : ;'  : |__'   .   . ||  |  ' | :'   ;   /|;  : |           |   :    |;  : |           
12|   | '  ,/ |  | '.'|`---`-'| ||  :  :_:,''   |  / ||  , ;            \   \  / |  , ;           
13;   : ;--'  ;  :    ;.'__/\_: ||  | ,'    |   :    | ---'              `----'   ---'            
14|   ,/      |  ,   / |   :    :`--''       \   \  /                                             
15'---'        ---`-'   \   \  /              `----'                                              
16  ,--,                 `--`-'                                                                   
17,--.'|                                                                                          
18|  | :     ,---.           .---.            __  ,-.                                             
19:  : '    '   ,'\         /. ./|          ,' ,'/ /|                                             
20|  ' |   /   /   |     .-'-. ' |   ,---.  '  | |' |                                             
21'  | |  .   ; ,. :    /___/ \: |  /     \ |  |   ,'                                             
22|  | :  '   | |: : .-'.. '   ' . /    /  |'  :  /                                               
23'  : |__'   | .; :/___/ \:     '.    ' / ||  | '                                                
24|  | '.'|   :    |.   \  ' .\   '   ;   /|;  : |                                                
25;  :    ;\   \  /  \   \   ' \ |'   |  / ||  , ;                                                
26|  ,   /  `----'    \   \  |--" |   :    | ---'                                                 
27 ---`-'              \   \ |     \   \  /                                                       
28                      '---"       `----'           '''
29
30VS = '''
31       ,---.             
32      /__./|             
33 ,---.;  ; |  .--.--.    
34/___/ \  | | /  /    '   
35\   ;  \ ' ||  :  /`./   
36 \   \  \: ||  :  ;_     
37  ;   \  ' . \  \    `.  
38   \   \   '  `----.   \ 
39    \   `  ; /  /`--'  / 
40     :   \ |'--'.     /  
41      '---"   `--'---'   '''
42      
Nesrine
14 Feb 2019
1data = [
2    {
3        'name': 'Instagram',
4        'follower_count': 346,
5        'description': 'Social media platform',
6        'country': 'United States'
7    },
8    {
9        'name': 'Cristiano Ronaldo',
10        'follower_count': 215,
11        'description': 'Footballer',
12        'country': 'Portugal'
13    },
14    {
15        'name': 'Kylie Jenner',
16        'follower_count': 172,
17        'description': 'Reality TV personality and businesswoman and Self-Made Billionaire',
18        'country': 'United States'
19    },
20    {
21        'name': 'Kim Kardashian',
22        'follower_count': 167,
23        'description': 'Reality TV personality and businesswoman',
24        'country': 'United States'
25    },
26    {
27        'name': 'Beyoncé',
28        'follower_count': 145,
29        'description': 'Musician',
30        'country': 'United States'
31    },
32    {
33        'name': 'Neymar',
34        'follower_count': 138,
35        'description': 'Footballer',
36        'country': 'Brasil'
37    },
38    {
39        'name': 'National Geographic',
40        'follower_count': 135,
41        'description': 'Magazine',
42        'country': 'United States'
43    },
44    {
45        'name': 'Justin Bieber',
46        'follower_count': 133,
47        'description': 'Musician',
48        'country': 'Canada'
49    },
50    {
51        'name': 'Taylor Swift',
52        'follower_count': 131,
53        'description': 'Musician',
54        'country': 'United States'
55    },
56    {
57        'name': 'Kendall Jenner',
58        'follower_count': 127,
59        'description': 'Reality TV personality and Model',
60        'country': 'United States'
61    },
62    {
63        'name': 'Nike',
64        'follower_count': 109,
65        'description': 'Sportswear multinational',
66        'country': 'United States'
67    },
68    {
69        'name': 'Khloé Kardashian',
70        'follower_count': 108,
71        'description': 'Reality TV personality and businesswoman',
72        'country': 'United States'
73    },
74    {
75        'name': 'Ellen DeGeneres',
76        'follower_count': 87,
77        'description': 'Comedian',
78        'country': 'United States'
79    },
80    {
81        'name': 'Real Madrid CF',
82        'follower_count': 86,
83        'description': 'Football club',
84        'country': 'Spain'
85    },
86    {
87        'name': 'FC Barcelona',
88        'follower_count': 85,
89        'description': 'Football club',
90        'country': 'Spain'
91    },
92    {
93        'name': 'Demi Lovato',
94        'follower_count': 80,
95        'description': 'Musician and actress',
96        'country': 'United States'
97    },
98    {
99        'name': "Victoria's Secret",
100        'follower_count': 69,
101        'description': 'Lingerie brand',
102        'country': 'United States'
103    },
104    {
105        'name': 'Zendaya',
106        'follower_count': 68,
107        'description': 'Actress and musician',
108        'country': 'United States'
109    },
110    {
111        'name': 'Chris Brown',
112        'follower_count': 64,
113        'description': 'Musician',
114        'country': 'United States'
115    },
116    {
117        'name': 'LeBron James',
118        'follower_count': 63,
119        'description': 'Basketball player',
120        'country': 'United States'
121    },
122    {
123        'name': 'Vin Diesel',
124        'follower_count': 62,
125        'description': 'Actor',
126        'country': 'United States'
127    },
128    {
129        'name': 'Cardi B',
130        'follower_count': 67,
131        'description': 'Musician',
132        'country': 'United States'
133    },
134    {
135        'name': 'Virat Kohli',
136        'follower_count': 55,
137        'description': 'Cricketer',
138        'country': 'India'
139    },
140    {
141        'name': 'Priyanka Chopra Jonas',
142        'follower_count': 53,
143        'description': 'Actress and musician',
144        'country': 'India'
145    }
146]