dimanche 15 mars 2020

A simple game,but can't get to stop the inputs at win condition,

How to play the game: You and the computer can enter any number 1,2 or 3, no more than 3. Once the sum of your and the bot's score is 15, the one with an odd total wins the game. Eg, at the end the total score is 15 and your score is 9 and the bot's score is 6, you win.

import random
total = 15
player = 0
bot = 0
score = 0
remaining = total - score

while score != total:

    score = player + bot
    remaining = total - score

    # printing the score
    print("Overall  --      Bot : ", bot, " You : ", player, " Remaining : ", remaining, "  Total : ", total)
    # win condition
    if score == total and player % 2 == 0:
        print("You lose!  :( ")
        break
    if score == total and bot % 2 == 0:
        print("You win!.  :)")
        break

     # player input
    x = int(input())
    if x > remaining:
        print("Limit exceeded.")
        continue
    if x in range(1, 4):
        player += x
    else:
        print("Choose a number from '1,2,3' ")
        continue
    score = score + player
    remaining = total - score
    #bot input
    if remaining <4:
        y = random.randrange(remaining)
    else:
        y = random.choice([1, 2, 3])
    bot += y
    print("You : ", x, "   Bot : ", y)



Aucun commentaire:

Enregistrer un commentaire