Question

PLEASE complete each task in python Write a console program that prompts the user for the...

PLEASE complete each task in python

Write a console program that prompts the user for the desired sum, then repeatedly rolls two six-sided dice (using a Random or RandomGenerator object to generate random numbers from 1-6) until the sum of the two dice values is the desired sum. Here is the expected dialogue with the user:

Desired sum: 9

4 and 3 = 7

3 and 5 = 8

5 and 6 = 1

1 5 and 6 = 11

1 and 5 = 6

6 and 3 = 9

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:-

import random #importing random library
desiredsum=int(input("Desired sum: ")) #taking integer input from the user
while(True): #loop
d1=random.randint(1,6) #getting random integer in the range(1 and 6)
d2=random.randint(1,6) #getting random integer in the range(1 and 6)
print(d1," and ",d2," = ",d1+d2);
if d1+d2==desiredsum: #if we get the desired sum
break #breaking the loop


Output:-

Add a comment
Know the answer?
Add Answer to:
PLEASE complete each task in python Write a console program that prompts the user for the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a class named DiceGame.java that contains a method called diceSum that prompts the use for...

    Write a class named DiceGame.java that contains a method called diceSum that prompts the use for a desired sum, then repeatedly simulates the rolling of 2 six-sided dice until their sum is the desired sum (use a do/while loop). Here is a sample dialogue with the user: Desired dice sum: 9 4 and 3 = 7 3 and 5 = 8 5 and 6 = 11 5 and 6 = 11 1 and 5 = 6 6 and 3 =...

  • question 2 in C programming please PE-05b-01 (Six-sider) write a counter-controlled program that prompts the user...

    question 2 in C programming please PE-05b-01 (Six-sider) write a counter-controlled program that prompts the user to enter the number of times n to roll a six-sided die. The program should print to the screen the iteration of the loop and result for each roll 1 ) How many times would you like to roll? 3 roll 6 6 5 1 2) PE 05b 02 (Flash Cards) Write a counter-controlled program that creates addition problems for an elementary kid to...

  • Write a C program that prompts the user for the number for times the user wants...

    Write a C program that prompts the user for the number for times the user wants to flip a coin. Your program will flip a virtual coin that number of times and return the following: 1) The number of times heads occurred. 2) The number of times tails occured. Then take the coin flip program and modify the random number generator to roll a single 6-sided dice.   DO NOT DISPLAY THE RESULTS OF EACH ROLL. 1) Ask the user how...

  • In python 3, Write a program in Python that simulates the roll of two dice. The...

    In python 3, Write a program in Python that simulates the roll of two dice. The first die is a 6-sided die. The second die is an 8-sided die. Generate a random number for a die and store it in variable number1. Generate a random number for a die and store it in variable number2. Note: Submit your code with the print("You rolled two dice:", number1, "and", number2) statement.

  • Write a Python program that prompts the user to enter integer values for each of two...

    Write a Python program that prompts the user to enter integer values for each of two lists. It then should displays whether the lists are of the same length, whether the elements in each list sum to the same value, and whether there are any values that occur in both lists.

  • Python 3 **11.40 (Guess the capitals) Write a program that repeatedly prompts the user to enter...

    Python 3 **11.40 (Guess the capitals) Write a program that repeatedly prompts the user to enter a capital for a state. Upon receiving the user input, the program reports whether the answer is correct. Assume that 50 states and their capitals are stored in a two- dimensional list, as shown in Figure 11.13. The program prompts the user to answer all the states’ capitals and displays the total correct count. The user’s answer is not case sensitive. Implement the program...

  • The Task: Create a console application that prompts the user to select either a stack, queue,...

    The Task: Create a console application that prompts the user to select either a stack, queue, linked list, or binary search tree. Then prompt the user for a number that will then be passed to a recursive function that will populate an array in ascending order. If user selected binary search tree, they will then be prompted to choose how the data will be received either in-order, preorder, or post-order. If user selected linked list, they will then be prompted...

  • Write a program that prompts the user for two integers and then prints The sum The...

    Write a program that prompts the user for two integers and then prints The sum The difference The product The average The distance (absolute value of the difference) The maximum (the larger of the two) The minimum (the smaller of the two) hint: python defines max and min functions that accept a sequence of values, each separated with a comma. **program must be written in Python**

  • please solve using python thank you! Write a program which prompts the user to enter a...

    please solve using python thank you! Write a program which prompts the user to enter a number of rows, and prints a hollow square star pattern with 2 diagonals. Note: you can assume that the integer will always be > 1 and will be an odd number. For example: Input Result 5 Enter number of rows: 5 ***** ** ** * * * ** ** ***** 9 Enter number of rows: 9 ** ** ** * * * * *...

  • Program must be in Python 3. Write a program that prompts the user to enter two...

    Program must be in Python 3. Write a program that prompts the user to enter two strings and then displays a message indicating whether or not the first string starts with the second string. Your program must satisfy the following requirements. 1. Your program must include a function called myStartsWith that takes two string parameters. This function returns True if the rst string starts with the second string and returns False otherwise. 2. Your program must include a main function...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT