0

Apologies for the noob question, I've only been programming for a month or so. I've created a Lucky 7s dice game, but when I tell it I don't want to play anymore, it continues asking. I think it has to do with on of the variables not being reassigned, but I'm not sure why. Here's the code I have written:

import random

#assign variables


times_played = 0 




#prompt user to bet
print('Would you like to play Lucky 7s? Type Yes or No.')
playing = input()


if playing == 'Yes' or 'yes':
    print('How much would you like to bet?')
    user_total = int(input('$ '))

while playing == 'Yes' or 'yes':

    die1 = random.randint(1,6)
    die2 = random.randint(1,6)
    dice_total = die1 + die2

    if dice_total == 7:
        print('You won $4!')
        times_played += 1
        user_total += 4
        print('You have $', user_total, '.')
        print('Would you like to keep playing?')
        playing == input()
        if playing == 'No' or playing =='no':
            break

    
    else:
        print('Sorry, you lost.')
        times_played += 1
        user_total -= 1
        print('You have $', user_total, '.')
        print('Would you like to keep playing?')
        playing == input()
        if playing == 'No' or playing =='no':
            break





print('Thanks for playing.')
print('You rolled', times_played, 'time(s).')
BenB
  • 21
  • 3
  • 2
    that's not how you compare a string against multiple values: https://stackoverflow.com/questions/6838238/comparing-a-string-to-multiple-items-in-python – Mahrkeenerh Oct 22 '21 at 13:35
  • 1
    Building on top of @Mahrkeenerh answer, non-empty string is a truthy value in Python so the line `playing == 'Yes' or 'yes'` will always evaluate to truth. – seqre Oct 22 '21 at 13:37
  • `playing == input()` should be: `playing = input()`. You can remove the final if statement. As suggested above, you need to use brackets when using `and` or `or` in your while loop: `while (playing == 'Yes') or (playing =='yes'):` – T C Molenaar Oct 22 '21 at 13:42

0 Answers0