Hello!
I have finished my first independent-project. I would really appreciate any feedback on how this could be improved or simplified.
Here is the code:
import random
gameloop = True
money = 100
wins = 0
loses = 0
name = input('\nPlease enter your username: ')
print('\nHello ' + name + '! You have $100 to spend')
while gameloop == True:
#User Story: As a user I want to be able to choose between the two guessing games at startup
game = input('\nDo you want to play "dices" or "flipcoin"?')
bet = int(input('\nEnter the ammount of your bet: '))
if bet <= money:
if game == 'flipcoin':
# User Story: As a user I want to be able to guess the outcome of a random coin flip(heads/tails).
y = input('\n"heads" or "tails"? ')
x = random.choice(['heads', 'tails'])
# User Story: As a user I want to clearly see the result of the coin flip.
# User Story: As a user I want to clearly see whether or not I guessed correctly.
if y == x:
res = bet
print ('\nYou choose ' + y + ' and the result was ' + x + ' ,you have earned $' + str(res))
else:
res = bet * -1
print('\nYou choose ' + y + ' and the result was ' + x + ' ,you have lost $'+ str(res))
elif game == 'dices':
#User Story: As a user I want to be able to guess the outcome of a 6-sided dice roll (1-6)
y = int(input('\nChoose a number between 1 and 6: '))
x = random.choice([1,2,3,4,5,6])
if y == x:
res = bet
print ('\nYou choose ' + str(y) + ' and the result was ' + str(x) + ' ,you have earned $' + str(res))
else:
res = bet * -1
print('\nYou choose ' + str(y) + ' and the result was ' + str(x) + ' ,you have lost $'+ str(res))
else:
print(game)
print('\nYou typed an invalid game option')
res = 0
money += res
if res > 0:
wins += 1
elif res < 0:
loses += 1
print('\nYour current balance is $' + str(money))
# User Story: As a user I want to clearly see the updated guess history (correct count/total count).
print('\nYour victory balance is wins: ' + str(wins) + ' loses: ' + str(loses))
# User Story: As a user I want to be able to quit the game or go again after each cycle and possibly even switch after each cycle.
else:
print('\nYour bet is higher than the ammount of money you have')
another_game = input('\nDo you want to play again? type ("yes"/"no): ')
if another_game == 'no':
gameloop = False
print('Thank you! Goodbye!')