0

I have created a while loop in which numbers are being generated, but I'm unable to make the loop continue when ever I add an user input command - which is the opposite of what I want. I want the loop to either continue or stop depending on what the user inputs. Someone please kindly help me out!

import random as r

lowest = 1
highest = 12
roll_counter = 0
roll = 'yes'
dont_roll = False

while roll == 'yes' or 'y':
    print(roll_counter)
    print('Rolling...')
    print('...the dice came out as', r.randint(lowest, highest), '-', r.randint(lowest, highest), '&', r.randint(lowest, highest), '-', r.randint(lowest, highest))
    roll_counter += 1
    if roll(input('Reroll? ')) == 'yes' or 'y':
        continue
    else:
        print('end')
        break
#This the hoped-for result (as viewed by user)
0 # I want the user to know how many rolls have taken place
Rolling...
...the dice came out as #number - #number & #number - #number
Reroll? yes #or y (for yes)
1
Rolling...
...the dice came out as #number - #number & #number - #number
Reroll? #any input other than 'yes' or 'y' would end the loop
End
wojackson
  • 1
  • 1
  • 1
    `while roll == 'yes' or 'y'` is not how you compare against multiple values; you should be doing `while roll in ['yes', 'y']` or `while roll == 'yes' or roll == 'y'`. You have the same mistake on the `roll(input('Reroll? ')) == 'yes' or 'y'` line too of course. But also that line doesn't make sense to me - why are you calling `roll()` as if it's a function? That's going to give the error "**TypeError: 'str' object is not callable**", because you're only assigning `str` values to `roll`. – Random Davis Oct 26 '22 at 16:04

0 Answers0