import random
def roll_dice():
dice_drawing = {
1:(
"_________",
"| 1 |",
"| * |",
"----------"
),
2:(
"__________",
"| 2 |",
"| * * |",
"-----------"
),
3:(
"__________",
"| 3 |",
"| * * * |",
"-----------"
),
4:(
"__________",
"| 4 |",
"| * * * * |",
"-----------"
),
5:(
"__________",
"| 5 * |",
"| * * * * |",
"-----------"
),
6:(
"__________",
"| * 6 * |",
"| * * * * |",
"-----------"
)
}
roll = input('Roll the dice Yes/No: ')
while roll.lower() == 'yes'.lower():
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
print('dice rolled: {} and {}'.format(dice1,dice2))
print("\n".join(dice_drawing[dice1]))
print("\n".join(dice_drawing[dice2]))
roll = input('Roll the dice Yes/No: ')
if roll not in roll:
roll = input('Roll the dice Yes/No: ')
roll_dice()
I am not able to understand if user types something else instead of yes
or no
, then I want the iteration to happen again saying invalid option please type yes or no
This code is working fine but what if user doesn't type yes or no type different key words than I want the iteration to run again saying its a invalid option please type yes or no , how to add this when user types wrong input which is defined by yes or no