Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

7.20 Chapter 7 Homework - Functions This lab requires you to write several functions. Some of your functions will be tested via unit tests and

image text in transcribedimage text in transcribed

7.20 Chapter 7 Homework - Functions This lab requires you to write several functions. Some of your functions will be tested via unit tests and some will be tested via output comparison. You should create a main() function to call some of your functions as described below. Make sure to provide a descriptive comment for each function. 1. Write a function called is_equal that takes two numbers and returns True if the numbers are equal and False if they are not equal. This function will be tested using unit tests and requires no input and does not need to be called from the main() function. 2. Write a function called my_random that takes two numbers, a low value and a high value. The function should generate two random numbers between the low value and high value and return the larger of the two. You should seed the random number generator with the value 10 (use random. seed (10) ). This function will be tested using unit tests and requires no input and does not need to be called from the main () function. 3. Write a function called roll_dice which takes, in order, a number representing the number of dice and a number representing the number of sides on the dice. The function should print a dice roll with a value between 1 and the number of sides on the die for each of the number of dice. You should seed the random number generator with the value 10. You should make two successive calls to this function using the arguments 4,8 and 5, 10. You may hard code these values into your main function. 4. Write a function called roll_no_pair_dice which takes, in order, a number representing the number of pairs of dice to roll and a number representing the number of sides on the dice. You should seed the random number generator with the value 10 . This version will roll pairs of dice, but will only count and print rolls where the two dice have different numbers. For instance, two rolls of two 6 same. You should make one call to this function using the arguments 5, 10. You may hard code these values into your main function. Load default template... 7.20 Chapter 7 Homework - Functions This lab requires you to write several functions. Some of your functions will be tested via unit tests and some will be tested via output comparison. You should create a main() function to call some of your functions as described below. Make sure to provide a descriptive comment for each function. 1. Write a function called is_equal that takes two numbers and returns True if the numbers are equal and False if they are not equal. This function will be tested using unit tests and requires no input and does not need to be called from the main() function. 2. Write a function called my_random that takes two numbers, a low value and a high value. The function should generate two random numbers between the low value and high value and return the larger of the two. You should seed the random number generator with the value 10 (use random. seed (10) ). This function will be tested using unit tests and requires no input and does not need to be called from the main () function. 3. Write a function called roll_dice which takes, in order, a number representing the number of dice and a number representing the number of sides on the dice. The function should print a dice roll with a value between 1 and the number of sides on the die for each of the number of dice. You should seed the random number generator with the value 10. You should make two successive calls to this function using the arguments 4,8 and 5, 10. You may hard code these values into your main function. 4. Write a function called roll_no_pair_dice which takes, in order, a number representing the number of pairs of dice to roll and a number representing the number of sides on the dice. You should seed the random number generator with the value 10 . This version will roll pairs of dice, but will only count and print rolls where the two dice have different numbers. For instance, two rolls of two 6 same. You should make one call to this function using the arguments 5, 10. You may hard code these values into your main function. Load default template

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions

Question

2. What should an employer do when facing an OSHA inspection?

Answered: 1 week ago