简体   繁体   中英

Game in Python (Dice)

my name is Erkan and i have problem with a game of dice im trying to build.

The core things i want to do is:

Ask the player of how many dices he wants. Minimun 1(ofc) and maximum 5. Each dice should only be tossed once.

The game should then randomizes results for each individual dice, one at a time, and prints this on the screen together with the sum of the tossed dice so far.

If any dice gets 1, then this is not added to the sum(like yatsy where im from), but two new dices are tossed. This should be displayed on the screen when / if it happens. As long as any dice gets 1, this procedure will repeat.

When all dice are tossed, the total sum and the number of dices tossed are printed on the screen. The player should then have the choice to play again or quit the game.

I'm very beginner at Python and sorry for bad english. Is it possible to get help on what im missing?

My code so far is this:

    from random import randint

   amount_dices=int(input("How many dices do you want to use? Min 1, max 5"))
   amount_dices_tossed = 1
    result=[]

    var1=0
    while var1<amount_dices_tossed:
     var1=var1+1
    for i in range(amount_dices):

     t=randint(1,6)
     result.append(t)
     print("Dices",i+1,":", t)
     Sum = sum(t)
     print(Sum)

    Sum_dices = int(sum())
    Sum_toss = str(sum(amount_dices_tossed))
    print("The total amount: " +Sum_dicesg + " and you tossed: " + Sum_tossed + " dices")

    choice = input("Do you want to play again? [yes/no]")
    answer1 = "yes"
    answer2 = "no"

    if choice == yes:

    else:
        print("Thanks for playing!")
        exit(0)

I dont know what it should say under "if choice == yes" when i want to start again.

To repeate code use loop while True and exit() or break to finish loop and finish game.

while True:

    # ... you code ...

    choice = input("Do you want to play again? [yes/no]")

    if choice != "yes":
        print("Thanks for playing!")
        #exit(0)
        break

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM