Concept explainers
Explanation of Solution
a.
#generating random int in the range 0-10 using random #function
random.randint(0, 10)
Explanation:...
Explanation of Solution
b.
#generating A random float in the range -0.5-0.5 using random #function
random.uniform(-0.5, 0.5)
Explanation:
Explanation of Solution
c.
#generating a random integer number representing the roll of #a six-sided die using random function.
random...
Explanation of Solution
d.
#generating a random integer number representing the sum #resulting from rolling two six-sided dice using random #function.
random.randint(1, 6) + random...
Explanation of Solution
e.
#generating a random float in the range -10.0-10.0 using #random function
random.uniform(-10.0, 10.0)
Explanation:
The above line of code is used to generate a random floating-point number between “-10.0” and “10.0” using random function.
Source code:
#import the required file
import random
#generating random int in the range 0-10 using random #function
print('A random int in the range 0–10 :', random.randint(0, 10))
#generating A random float in the range -0.5-0.5 using random #function
print('A random float in the range -0.5–0.5 :', random.uniform(-0.5, 0.5))
#generating a random integer number representing the roll of #a six-sided die using random function.
# roll of six-sided die means 1-6
print('A random number representing the roll of a six-sided die :', random.randint(1, 6))
#generating a random integer number representing the sum #resulting from rolling two six-sided dice using random #function.
print('A random number representing the sum resulting from rolling two six-sided dice : ',
random.randint(1, 6) + random.randint(1, 6))
#generating a random float in the range -10...
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
- (Simulation) Write a program to simulate the roll of two dice. If the total of the two dice is 7 or 11, you win; otherwise, you lose. Embellish this program as much as you like, with betting, different odds, different combinations for win or lose, stopping play when you have no money left or reach the house limit, displaying the dice, and so forth. (Hint: Calculate the dots showing on each die with the expression dots=(int)(6.0randomnumber+1), where the random number is between 0 and 1.)arrow_forwardint y=0,i; for (int i=0;i<10;++i) y+=i; 36 66 45 55arrow_forwardQ5: - Write program to calculate the equation sin(x) y(x) = x * where x= 0.1,0.2,0.3,0.4arrow_forward
- Write a Phyton program that computes the duration of a projectile’s flight and its height above the ground when it reaches the target. As part of your solution, you should display instructions to the program user. Relevant formula: time = distancevelocity xcos (θ) height = velocity xsin x time- g x time22 use the following variables: g = gravitational constant = 32.17 = angle of elevation in radian v = velocity or the projectile velocity (ft/sec) d= distance to target t = time of flight in seconds. h = height at impact Try your program on these data sets.arrow_forwardLet H be "The weather is hot" and D be " The weather is dry ", then the statement "it is false that, the weather is not hot or dry " can be written in logical notation as Select one: -(-H) v D -(Hv -D) -(-H v D) -(H v D)arrow_forwardGiven an airplane’s acceleration a and take-off speed v, you can compute the minimum runway length needed for an airplane to take off using the following formula: length = v2/2a Write a program that prompts the user to enter v in meters/second (m/s) and the acceleration a in meters/second squared and displays the minimum runway length.arrow_forward
- If a certain odd integer is represented by the expression 2n - 1, write an expression for the next odd integer.arrow_forward4) Roll the dice 2 Make a program that tests the probability of a certain score when rolling x dice. The user should be able to choose to roll eg 4 dice and test the probability of a selected score eg 11. The program should then do a number of simulations and answer how big the probability is for the selected score with as many dice selected. There must be error checks so that you cannot enter incorrect sums, for example, it is not possible to get the sum 3 if you roll 4 dice. TarningsKast2 How many dices do you want to throw? 11 Which number do you want the probability for? The probability the get the number 11 with 4 dices is 7.19% Calculatearrow_forwardThe area of a pentagon can be computed using the following formula (s is the length of a side): Area = ( 5 * s2 ) / ( 4 * tan( π/5 ) Write a program that prompts the user to enter the side of a pentagon and displays the area.arrow_forward
- Problem: A small company needs an interactive program to compute an employee’s paycheck. The payroll clerk will initially input the data, and given the input data, an employee's wage for the week should be displayed on the screen for the payroll check. The data for the employee includes the employee's hourly pay rate and the number of hours worked that week. Wage is equal to the employee's pay rate times the number of hours worked (up to 40 hours). If the employee worked more than 40 hours, wage is equal to the employee's pay rate times 40 hours plus 1½ times the employee's pay rate times the number of hours worked above 40. Instructions: Match the action at the left-side with the correct step number at the right-side (the attached picture). Note that it may be possible to group more than one related actions in the same logical step / process without altering the essence of the algorithm. In the program flow, input and checking of hourly pay rate should come before that of the number…arrow_forwardWrite a program to generate a random number between 1 - 100, and then display which quartile the number falls in. First quartile is 1 - 25 Second quartile is 26 - 50 Third quartile is 51 - 75 Fourth quartile is 76 - 100 To generate a random number, follow these steps: include necessary header files #include <cstdlib> //for random functions #include <ctime> //for time functions set constants for the minimum and maximum values of the desired range const int MIN_VALUE = 1; //minimum range value const int MAX_VALUE = 100; //maximum range value seed the random number generator (RNG) with a unique unsigned int value - system time! unsigned seed = time(0); //system time in seconds since 1/1/1970 srand(seed); //seed the RNG get a random number in the desired range int num = (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE; The program should: contain header comments as shown in class display a "hello" message (more descriptive than shown in sample) generate…arrow_forwardFinancial application: compute future apartment rent) Suppose that the rent for an apartment is $1000 thisyear and increases 3% every year. Write a program that computes the rent in five years and the total rent forone year starting five years from now.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning