|
1 | 1 | # Nothing for a Pair (not in this game) |
| 2 | +# Amended after the images were created to add the option to loop the game |
| 3 | +# Amended to simplify the data entry |
2 | 4 |
|
3 | 5 | # imports |
4 | 6 | import random |
|
17 | 19 | a_suite.append("Hearts") |
18 | 20 | a_suite.append("Spades") |
19 | 21 |
|
| 22 | +a_guesses={"H": "Higher", "L": "Lower", "": "Invalid Guess"} |
| 23 | + |
20 | 24 | s_success="Congratulations! You're a Winner!" |
21 | 25 | s_failure="Better luck next time :(" |
22 | 26 | s_invalid="Sorry your guess wasn't understood" |
23 | 27 |
|
24 | 28 | print ( "Higher or Lower - Come on Down " ) |
25 | 29 | print ( "-" * 40) |
26 | 30 |
|
27 | | -# deal card |
28 | | -i_card = random.randint(1,13) |
29 | | -i_suite = random.randint(1,4) |
| 31 | +while True: |
| 32 | + # deal card |
| 33 | + i_card = random.randint(1,13) |
| 34 | + i_suite = random.randint(1,4) |
30 | 35 |
|
31 | | -print ( f'Your first card {i_card} is a {a_cards[i_card]} of {a_suite[i_suite]}') |
| 36 | + print ( f'Your first card {i_card} is a {a_cards[i_card]} of {a_suite[i_suite]}') |
32 | 37 |
|
33 | | -your_guess = input("Please enter if you think the next card will be 'higher' or 'lower' :").lower() |
| 38 | + your_guess = input("Please enter if you think the next card will be higher (H) or lower (L) :").upper() |
34 | 39 |
|
35 | | -print ( f'You guessed {your_guess} ') |
| 40 | + print ( f'You guessed {a_guesses[your_guess]} ') |
36 | 41 |
|
37 | | -# deal card |
38 | | -i_card_2 = random.randint(1,13) |
39 | | -i_suite_2 = random.randint(1,4) |
| 42 | + # deal card |
| 43 | + i_card_2 = random.randint(1,13) |
| 44 | + i_suite_2 = random.randint(1,4) |
40 | 45 |
|
41 | | -print ( f'Your second card {i_card_2} is a {a_cards[i_card_2]} of {a_suite[i_suite_2]}') |
| 46 | + print ( f'Your second card {i_card_2} is a {a_cards[i_card_2]} of {a_suite[i_suite_2]}') |
42 | 47 |
|
43 | | -if your_guess=="higher" : |
44 | | - if i_card < i_card_2 : |
45 | | - print ( s_success ) |
46 | | - else : |
47 | | - print ( s_failure ) |
48 | | -elif your_guess=="lower" : |
49 | | - if i_card > i_card_2 : |
50 | | - print ( s_success ) |
| 48 | + if your_guess=="H" : |
| 49 | + if i_card < i_card_2 : |
| 50 | + print ( s_success ) |
| 51 | + else : |
| 52 | + print ( s_failure ) |
| 53 | + elif your_guess=="L" : |
| 54 | + if i_card > i_card_2 : |
| 55 | + print ( s_success ) |
| 56 | + else : |
| 57 | + print ( s_failure ) |
51 | 58 | else : |
52 | | - print ( s_failure ) |
53 | | -else : |
54 | | - print ( s_invalid ) |
55 | | - print ( s_failure ) |
| 59 | + print ( s_invalid ) |
| 60 | + print ( s_failure ) |
| 61 | + |
| 62 | + # play again? |
| 63 | + f_cont = input( f'Do you want to play again? (Y/N) ').lower() |
| 64 | + if f_cont=="n": |
| 65 | + print ( '=' * 40 ) |
| 66 | + print ( 'Thanks for playing, see you soon' ) |
| 67 | + break |
| 68 | + else: |
| 69 | + print ( '-' * 40 ) |
0 commit comments