1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Arada [10]
1 year ago
14

Write a program that allows a user to choose to roll between 1 and 100 dice between 1 and 1000 times

Computers and Technology
1 answer:
s344n2d4d5 [400]1 year ago
8 0

Answer:

Here is a Python program that allows a user to choose to roll between 1 and 100 dice between 1 and 1000 times. The program uses a while loop to continuously prompt the user for input until they enter a valid number of dice and rolls. It also uses a for loop to simulate the dice rolls and a random module to generate random numbers for the dice rolls.

import random

while True:

   # Prompt the user for the number of dice to roll

   num_dice = int(input("Enter the number of dice to roll (1-100): "))

   if num_dice < 1 or num_dice > 100:

       continue

   # Prompt the user for the number of rolls to perform

   num_rolls = int(input("Enter the number of rolls to perform (1-1000): "))

   if num_rolls < 1 or num_rolls > 1000:

       continue

   # Simulate the dice rolls and print the results

   for i in range(num_rolls):

       roll = 0

       for j in range(num_dice):

           roll += random.randint(1, 6)

       print(f"Roll {i+1}: {roll}")

   # Ask the user if they want to roll again

   again = input("Roll again? (Y/N): ").upper()

   if again != "Y":

       break

Explanation:

In this program, we first import the random module to use its randint function to generate random numbers for the dice rolls. We then enter a while loop that will continuously prompt the user for input until they enter a valid number of dice and rolls. Within the while loop, we prompt the user for the number of dice to roll and the number of rolls to perform. If the user enters an invalid number of dice or rolls, we continue back to the beginning of the loop and prompt the user again.

Once the user has entered a valid number of dice and rolls, we use a for loop to simulate the dice rolls. For each roll, we use another for loop to roll the specified number of dice and add up the results. We then print the total for each roll. After all of the rolls have been performed, we ask the user if they want to roll again. If they enter "Y", we continue back to the beginning of the while loop to prompt them for new input. If they enter anything else, we break out of the while loop and end the program.

Overall, this program allows a user to choose to roll between 1 and 100 dice between 1 and 1000 times, and simulates the dice rolls using random numbers and loops.

You might be interested in
The large structure that supports a spacecraft prior to launch is called the
OlgaM077 [116]
Launch tower

Hope that helps
         

7 0
3 years ago
If you must use a credit card while in college what are some ways you can keep from getting in credit card debt?
marin [14]

Answer:

Pay attention to what you buy and limit yourself to an amount of money everyday.

Explanation:

This is just a simple way from spending a lot and limits your everyday spendings when you actually leave an amount for yourself.

3 0
4 years ago
Write a program for a grocery store to calculate the total charge for customers. In the main: Your program should ask customer t
gavmur [86]

Answer:

Hello Joelwestwood! This is a good question to check your knowledge of subrountines and Arrays. Please find the implementation with the explanation below.

Explanation:

The solution can be implemented in a number of languages including C++, Java and Python to name a few. Though the implementation language is not specified in the question, i'll provide you the implementation code in Python and also in Java. Java implementation is a little complex because we need to define an array size to be able to add items to it, whereas Python allows us more flexibility by allowing dynamic size of Array.

JAVA IMPLEMENTATION

import java.util.Scanner;

import java.util.Arrays;

class TotalCharge {

 private static int[] price_array = new int[1];

 public void FillPriceArray(int price) {

   if (price_array.length == 1) {

     price_array[0] = price;

   } else {

     price_array = new int[price_array.length + 1];

     price_array[price_array.length + 1] = price;

   }

 }

 public int[] get_price_array() {

   return price_array;

 }

 public static void main(String args[]) {

   System.out.println("Please enter the total number of items to purchase: ");

   Scanner scan = new Scanner(System.in);

   int price = scan.nextInt();

   if (price <= 20) {

     System.out.println("Items being purchased are less than 20");

   } else {

     System.out.println("Items being purchased are more than 20");

   }

   TotalCharge itemsTotal = new TotalCharge();

   itemsTotal.FillPriceArray(price);

   System.out.println(Arrays.toString(itemsTotal.get_price_array()));

 }

}

PYTHON IMPLEMENTATION

calculate_total_charge.py

def FillPriceArray(price):

 price_array.append(price)

price_array = []

price = raw_input("Please enter the total number of items to purchase: ")

try:

 price = int(price)

 if price <= 20:

   print("Items being purchased are less than 20")

 else:

   print("Items being purchased are more than 20")

 FillPriceArray(price)

 print(price_array)

except ValueError:

 print("Invalid input! Exiting..")

8 0
3 years ago
4. A friend knows you are taking a technology class in college and asks you how a hard drive works. In your own words, describe
sveticcg [70]
Keep it simple... it holds whatever info' you want. would he/she understand?


3 0
3 years ago
Read 2 more answers
I was just called a man in a wig ugh <br><br> Any tips for doxxing someone?
kondaur [170]

Answer:

Explanation:

hope this help

6 0
2 years ago
Other questions:
  • If a given router can connect to at most k networks, how many routers, r, are required to connect n networks? write an equation
    7·1 answer
  • David has a laptop that is having a problem with the video system. You believe the problem might be the backlight. During your r
    13·1 answer
  • What is important for an internet user to know about https:// ?
    9·1 answer
  • What is the use of html in websites
    15·2 answers
  • Which of the following is a typical concern for developers while using prototypes?
    6·2 answers
  • Assume that an array named salarySteps whose elements are of type int and that has exactly five elements has already been declar
    11·1 answer
  • A certain string-processing language offers a primitive operation which splits a string into two pieces. Since this operation in
    10·1 answer
  • Write a program that reads a list of words. Then, the program outputs those words and their frequencies. Ex: If the input is: he
    8·1 answer
  • Which is an example of an input device?
    6·2 answers
  • can you follow my ikok? its that_enby_skye and my youube Cactus Face with 241 subscribe er s &amp; my twith Mx_Skye
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!