212k views
18 votes
Write a program that asks the user to guess the next roll of a six-sided die. Each guess costs $ 1. If they guess correctly, they get $ 100.00. The player will start out with a $10.00 bank. Each time he (or she) guesses incorrectly you will subtract $1.00 from their bank. Each time they guess correctly, you add $10.00 to their bank. Print the total winnings or losses at the end of the game. You can simulate the toss of the dice using the RandomRange function (Don't forget to Randomize).

User Zeekstem
by
7.6k points

1 Answer

9 votes

Answer in python:

import random

money = 10

winnings = 0

def main():

global winnings

global money

dice_num = random.randrange(1,6)

input_str = "Guess the dice number. You have $"+str(money)+" > "

input_num = input(input_str)

if int(input_num) == dice_num:

money = money + 10

winnings = winnings + 10

else:

money = money - 1

if money < 0:

print("You lose. You won "+str(winnings)+" times. Press enter to try again")

useless_variable = input()

main()

else:

main()

main()

Step-by-step explanation:

User Leon Latsch
by
7.9k points