Ok, so totally green but super keen!
I programmed a 'dice' attack value game, that prompts a user to choose n die to roll and with what 'attack value' the dice will have. the object is for a war board game, not important... Program seems to run fine, but sometimes it runs the 'for' loop more times than the user prompted for.... What am I doing wrong with this for loop? (code below)
I programmed a 'dice' attack value game, that prompts a user to choose n die to roll and with what 'attack value' the dice will have. the object is for a war board game, not important... Program seems to run fine, but sometimes it runs the 'for' loop more times than the user prompted for.... What am I doing wrong with this for loop? (code below)
while True: print("welcome to the dice game!") import random a=input("how many die would you like to roll? ") b=input("what is the attack value of the die? ") aa=int(a) bb=int(b) print('OK... anything ',b,'or less, is a hit!') print('Here we go!') hit=0 miss=0 for x in iter(aa): j=random.randint(1,6) if j<=bb: print(j,'hit') j=hit hit=hit+1 if j>bb: print(j,'miss') j=miss miss=miss+1 print('total hits: ',hit) print('total misses: ',miss) y=input('would you like to play again (y/n)') if y=='y': continue if y=='n': break if y!='y' and y!='n': print('invalid answer') break print('thanks for playing!')also not sure how to paste code to include indentation on this forum... sorry.