-3
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

kuro
  • 3,214
  • 3
  • 15
  • 31
  • You can change `if roll not in roll` to `while roll.lower() not in ('yes', 'no')` and put a print saying invalid input inside the loop just before the `input()` call – kuro Nov 23 '22 at 04:48

1 Answers1

-1

is this you are finding ?

while True:
    roll = input('Roll the dice Yes/No: ')
    if roll.lower() == 'yes':
        
        ##
        ## do your stuff here 
        ##

    elif roll.lower() =='no':
        break
    else :
        print('enter yes or no')