Discover a wealth of knowledge at Westonci.ca, where experts provide answers to your most pressing questions. Discover solutions to your questions from experienced professionals across multiple fields on our comprehensive Q&A platform. Get precise and detailed answers to your questions from a knowledgeable community of experts on our Q&A platform.

If anyone knows how to code on python:
I need to write a program that asks the user for two dice rolls and will tell the user to advance the number spaces coressponeing to the total rolled.

Etc.
Enter first roll: 4
Enter second roll: 6
Advance 10 spaces

The code should include a message for invalid rolls, and should also tell the user to roll again if they roll the same two numbers. Someone please help me out!


Sagot :

Answer:

def dice_roller():

   # ask for first input

   input1 = int(input("Enter the first roll: "))

   # check if it's valid

   while input1 < 1 or input1 > 6:

       print("Invalid number")

       # ask for new input if the previous was invalid

       input1 = int(input("Enter the first roll: "))

   # ask for second input

   input2 = int(input("Enter the second roll: "))

   # check if it's valid

   while input2 < 1 or input2 > 6:

       print("Invalid number")

       # ask for new input if the previous was invalid

       input2 = int(input("Enter the second roll: "))

   # check of the numbers are the same

   if input1 == input2:

       print("You rolled the same numbers. Try again")

       # if they are the same call this function again to get new numbers

       dice_roller()

   else:

       # print how many spaces to advance

       print("Advance", input1+input2, "spaces")

if __name__ == '__main__':

   dice_roller()

View image kenshri1
We hope this information was helpful. Feel free to return anytime for more answers to your questions and concerns. We appreciate your time. Please revisit us for more reliable answers to any questions you may have. Westonci.ca is committed to providing accurate answers. Come back soon for more trustworthy information.