Add formated and linted update

This commit is contained in:
Laird Streak
2021-02-16 18:52:07 +13:00
parent c5e11d4d9d
commit d71c0fd36b
3 changed files with 53 additions and 39 deletions

View File

@@ -1,3 +1,5 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html) Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Python](https://www.python.org/about/) Conversion to [Python](https://www.python.org/about/)
Propose using pylint and black to format python files so that it conforms to some standards

View File

@@ -24,6 +24,7 @@ cards = {
def play_game(): def play_game():
"""Play the game"""
cash = 100 cash = 100
while cash > 0: while cash > 0:
print(f"You now have {cash} dollars\n") print(f"You now have {cash} dollars\n")
@@ -63,6 +64,7 @@ def play_game():
def main(): def main():
"""Main"""
keep_playing = True keep_playing = True
while keep_playing: while keep_playing:

View File

@@ -1,3 +1,4 @@
"""aceyducey.py contains game code"""
######################################################## ########################################################
# #
# Acey Ducey # Acey Ducey
@@ -31,19 +32,35 @@ DEFAULT_BANKROLL = 100
# functions # functions
def deal_card_num(): def deal_card_num():
"""Get card number"""
return random.randint(0, 12) 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): def get_card_name(number):
if bankroll > 0: """Get card name"""
print("You now have %s dollars\n"%b) 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 # Display initial title and instructions
print("\n Acey Ducey Card Game") print("\n Acey Ducey Card Game")
@@ -58,15 +75,15 @@ print("If you do not want to bet, input a 0")
# Loop for series of multiple games # Loop for series of multiple games
keep_playing = True KEEP_PLAYING = True
while keep_playing: while KEEP_PLAYING:
# Initialize bankroll at start of each game # Initialize bankroll at start of each game
bankroll = DEFAULT_BANKROLL BANK_ROLL = DEFAULT_BANKROLL
display_bankroll(bankroll) display_bankroll(BANK_ROLL)
# Loop for a single round. Repeat until out of money. # Loop for a single round. Repeat until out of money.
while bankroll > 0: while BANK_ROLL > 0:
# Deal out dealer cards # Deal out dealer cards
print("Here are your next two cards") print("Here are your next two cards")
@@ -76,45 +93,45 @@ while keep_playing:
while dealer1 == dealer2: while dealer1 == dealer2:
dealer2 = deal_card_num() dealer2 = deal_card_num()
# Organize the cards in order if they're not already # Organize the cards in order if they're not already
if (dealer1 >= dealer2): if dealer1 >= dealer2:
(dealer1, dealer2) = (dealer2, dealer1) # Ya gotta love Python! (dealer1, dealer2) = (dealer2, dealer1) # Ya gotta love Python!
# Show dealer cards to the player # Show dealer cards to the player
# (use card name rather than internal number) # (use card name rather than internal number)
print(get_card_name(dealer1)) print(get_card_name(dealer1))
print(get_card_name(dealer2) + "\n") print(get_card_name(dealer2) + "\n")
# Get and handle player bet choice # Get and handle player bet choice
bet_is_valid = False BET_IS_VALID = False
while not bet_is_valid: while not BET_IS_VALID:
curr_bet = input("What is your bet? ") curr_bet = input("What is your bet? ")
try: try:
curr_bet = int(curr_bet) curr_bet = int(curr_bet)
except: except ValueError:
# Bad input? Just loop back up and ask again... # Bad input? Just loop back up and ask again...
pass pass
else: else:
if curr_bet == 0: if curr_bet == 0:
bet_is_valid = True BET_IS_VALID = True
print("Chicken!!\n") print("Chicken!!\n")
elif curr_bet > bankroll: elif curr_bet > BANK_ROLL:
print("Sorry, my friend but you bet too much") 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: else:
# Deal player card # Deal player card
bet_is_valid = True BET_IS_VALID = True
player = deal_card_num() player = deal_card_num()
print(get_card_name(player)) print(get_card_name(player))
# Did we win? # Did we win?
if player > dealer1 and player < dealer2: if dealer1 < player < dealer2:
print("You win!!!") print("You win!!!")
bankroll += curr_bet BANK_ROLL += curr_bet
else: else:
print("Sorry, you lose") print("Sorry, you lose")
bankroll -= curr_bet BANK_ROLL -= curr_bet
# Update player on new bankroll level # Update player on new bankroll level
display_bankroll(bankroll) display_bankroll(BANK_ROLL)
# End of loop for a single round # End of loop for a single round
@@ -123,7 +140,7 @@ while keep_playing:
if player_response.lower() == "yes": if player_response.lower() == "yes":
print() print()
else: else:
keep_playing = False KEEP_PLAYING = False
# End of multiple game loop # End of multiple game loop
@@ -187,10 +204,3 @@ print("OK Hope you had fun\n")
# get their own player card dealt). # get their own player card dealt).
# #
######################################################## ########################################################