Games of change advice

Hi

I just have one question, I’m just doing a project in python after flow control, what It did it’s working and I found I can’t use input function in the web for enter data.

So this is my code, what recommendation will you give me to improve what I did?

import random

money = 100  # This variable will measure if the money is more or les

# I will create my functions below
# Function to make a new call and new flip
def coin_call():
  coin = ('Heads', 'Tails')
  coin = random.choice(coin)
  print(coin)
  return coin

def coin_flip():
  flipresult = ('Heads', 'Tails')
  flipresult = random.choice(flipresult)
  print(flipresult)
  return flipresult

# Flipping coin game
def coin_game(call, bet,flip):
  global money
  if call == 'Heads' and flip == 'Tails':
    money -= bet
    print("you just lost " + " your current balance is: " + str(money) + " USD")
  elif call == 'Heads' and flip == 'Heads':
    money = money + bet
    print("you just won " + " your current balance is: " + str(money) + " USD")
  elif call == 'Tails' and flip == 'Heads':
    money = money - bet
    print("you just lost " + " your current balance is: " + str(money) + " USD")
  elif call == 'Tails' and flip == 'Tails':
    money = money + bet
    print("you just won " + " your current balance is: " + str(money) + " USD")

# Calling my functions with values for coin flip exercise

while money > 0:
  bet = 50
  if bet <= money and bet > 0:
    coin_game(coin_call(),bet,coin_flip())
  elif bet > money:
    print('You aint got that ammount')
    break
  else:
    print('you cant bet negative numbers')
    break

Nothing beats one’s own scrutiny, consistently. Over and over and over again. It’s what helps us spot repetition and ways to express in a singular way, those repetitions.

return random.choice(('Heads', 'Tails'))

Thanks for the advice , I will use it and keep that in mind to reduce lines in the code. thank you sir

1 Like