From d71c0fd36ba2cb1c84d70acd19806189a1ae98e9 Mon Sep 17 00:00:00 2001 From: Laird Streak Date: Tue, 16 Feb 2021 18:52:07 +1300 Subject: [PATCH] Add formated and linted update --- 01 Acey Ducey/python/README.md | 2 + 01 Acey Ducey/python/acey_ducey.py | 4 +- 01 Acey Ducey/python/aceyducey.py | 86 +++++++++++++++++------------- 3 files changed, 53 insertions(+), 39 deletions(-) diff --git a/01 Acey Ducey/python/README.md b/01 Acey Ducey/python/README.md index 781945ec..e5e1f207 100644 --- a/01 Acey Ducey/python/README.md +++ b/01 Acey Ducey/python/README.md @@ -1,3 +1,5 @@ Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html) Conversion to [Python](https://www.python.org/about/) + +Propose using pylint and black to format python files so that it conforms to some standards diff --git a/01 Acey Ducey/python/acey_ducey.py b/01 Acey Ducey/python/acey_ducey.py index ad779a5d..6832c7e0 100644 --- a/01 Acey Ducey/python/acey_ducey.py +++ b/01 Acey Ducey/python/acey_ducey.py @@ -24,6 +24,7 @@ cards = { def play_game(): + """Play the game""" cash = 100 while cash > 0: print(f"You now have {cash} dollars\n") @@ -63,6 +64,7 @@ def play_game(): def main(): + """Main""" keep_playing = True while keep_playing: @@ -75,7 +77,7 @@ if __name__ == "__main__": print( """ Acey-Ducey is played in the following manner -The dealer (computer) deals two cards face up +The dealer (computer) deals two cards face up You have an option to be or not bet depending on whether or not you feel the card will have a value between the first two. diff --git a/01 Acey Ducey/python/aceyducey.py b/01 Acey Ducey/python/aceyducey.py index c995b836..9aaef681 100644 --- a/01 Acey Ducey/python/aceyducey.py +++ b/01 Acey Ducey/python/aceyducey.py @@ -1,3 +1,4 @@ +"""aceyducey.py contains game code""" ######################################################## # # Acey Ducey @@ -31,18 +32,34 @@ DEFAULT_BANKROLL = 100 # functions def deal_card_num(): + """Get card number""" return random.randint(0, 12) -def get_card_name(n): - cardNames = (" 2", " 3", " 4", " 5", " 6", \ - " 7", " 8", " 9", " 10", "Jack", \ - "Queen", "King", "Ace") - return(cardNames[n]) -def display_bankroll(b): - if bankroll > 0: - print("You now have %s dollars\n"%b) - +def get_card_name(number): + """Get card name""" + card_names = ( + " 2", + " 3", + " 4", + " 5", + " 6", + " 7", + " 8", + " 9", + " 10", + "Jack", + "Queen", + "King", + "Ace", + ) + return card_names[number] + + +def display_bankroll(bank_roll): + """Print current bankroll""" + if BANK_ROLL > 0: + print("You now have %s dollars\n" % bank_roll) # Display initial title and instructions @@ -58,15 +75,15 @@ print("If you do not want to bet, input a 0") # Loop for series of multiple games -keep_playing = True -while keep_playing: - +KEEP_PLAYING = True +while KEEP_PLAYING: + # Initialize bankroll at start of each game - bankroll = DEFAULT_BANKROLL - display_bankroll(bankroll) + BANK_ROLL = DEFAULT_BANKROLL + display_bankroll(BANK_ROLL) # Loop for a single round. Repeat until out of money. - while bankroll > 0: + while BANK_ROLL > 0: # Deal out dealer cards print("Here are your next two cards") @@ -76,46 +93,46 @@ while keep_playing: while dealer1 == dealer2: dealer2 = deal_card_num() # Organize the cards in order if they're not already - if (dealer1 >= dealer2): - (dealer1, dealer2) = (dealer2, dealer1) # Ya gotta love Python! + if dealer1 >= dealer2: + (dealer1, dealer2) = (dealer2, dealer1) # Ya gotta love Python! # Show dealer cards to the player # (use card name rather than internal number) print(get_card_name(dealer1)) print(get_card_name(dealer2) + "\n") # Get and handle player bet choice - bet_is_valid = False - while not bet_is_valid: + BET_IS_VALID = False + while not BET_IS_VALID: curr_bet = input("What is your bet? ") try: curr_bet = int(curr_bet) - except: + except ValueError: # Bad input? Just loop back up and ask again... pass else: if curr_bet == 0: - bet_is_valid = True + BET_IS_VALID = True print("Chicken!!\n") - elif curr_bet > bankroll: + elif curr_bet > BANK_ROLL: print("Sorry, my friend but you bet too much") - print("You have only %s dollars to bet\n" % bankroll) + print("You have only %s dollars to bet\n" % BANK_ROLL) else: # Deal player card - bet_is_valid = True + BET_IS_VALID = True player = deal_card_num() print(get_card_name(player)) - + # Did we win? - if player > dealer1 and player < dealer2: + if dealer1 < player < dealer2: print("You win!!!") - bankroll += curr_bet + BANK_ROLL += curr_bet else: print("Sorry, you lose") - bankroll -= curr_bet + BANK_ROLL -= curr_bet # Update player on new bankroll level - display_bankroll(bankroll) - + display_bankroll(BANK_ROLL) + # End of loop for a single round print("\n\nSorry, friend but you blew your wad") @@ -123,7 +140,7 @@ while keep_playing: if player_response.lower() == "yes": print() else: - keep_playing = False + KEEP_PLAYING = False # End of multiple game loop @@ -187,10 +204,3 @@ print("OK Hope you had fun\n") # get their own player card dealt). # ######################################################## - - - - - - -