mardi 30 août 2022

Can't figure out program for dice rolls, rerolls, and printing number of successes

Fairly new to coding. Trying to program a way to roll bulk dice, reroll certain numbers once, and then print how many dice were equal to or above the value needed. I can't find any examples to work off of or understand if I'm on the right track. Any assistance is appreciated. Thank you!

import random

while True:

user_amount = int(input("Roll how many dice?: "))
user_reroll = int(input("Reroll what numbers? (Put 0 for no reroll): "))
user_value = int(input("Keep what value and above?: "))`

dice = random.randint(1,6) #dice
roll = (dice, range(user_amount)) 

for dice in roll:
    if user_reroll == 0:
        break
    else:
        if user_reroll == dice:
            dice
            break
for dice in roll:
    if dice >= user_value:
        success = str(roll)
        print(len(success))
while True: 
    answer = str(input('Roll again? (y/n): '))
    if answer in ('y', 'n'):
        break
    print("invalid input.")
if answer == 'y':
    continue
else:
    print("The Emperor protects")
    break



Aucun commentaire:

Enregistrer un commentaire