Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WEEK 3 LAB This week, we will discuss about functions and file handling. Functions Exercise 1. Write a function to find out the maximum value

image text in transcribedimage text in transcribed

WEEK 3 LAB This week, we will discuss about functions and file handling. Functions Exercise 1. Write a function to find out the maximum value of three numbers. Utilize the function, ask user to enter three numbers and print out the maximum value of those three numbers. In [ ]: Exercise 2. Create a function to roll a dice and utilize it to develop a game of chance as described below: A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5 and 6 spots. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on the first throw, the player wins. If the sum is 2, 3 or 12 on the first throw (called "craps"), the player loses (i.e., the "house" wins). If the sum is 4, 5, 6, 8, 9 or 10 on the first throw, then that sum becomes the player's "point." To win, you must continue rolling the dice until you "make your point" (as same current point). The player loses by rolling a 7 before making the point. Note: utilize function random.randrange to create a function to roll a dice.** First part Create a function to roll a dice. This function needs to generate 2 random numbers from 1 to 6 and return the sum of numbers. You can utilize function random.randrange to create a function to roll a dice. In [ ]: Second part Call the function created above. Use conditional statements to do the following: If the sum is 7 or 11 on the first throw, the player wins. If the sum is 2, 3 or 12 on the first throw (called "craps"), the player loses (i.e., the "house" wins). If the sum is 4, 5, 6, 8, 9 or 10 on the first throw, then that sum becomes the player's "point." If the player neither looses or wins on the first throw, you need to use loop to continue the game. To win, you must continue rolling the dice until you make your point" (as same current point). The player loses by rolling a 7 before making the point. File Handling Exercise 3. Develop a program that will open a file named "data.dat" for reading ("data.dat" has been given along with the assignment in BB). This file will contain an unknown number of values that should be read in and then averaged together. The data file will be written such that each line contains 1 record. The data contained in this file should then be averaged together by using a function and the number of items and the average of the items should be printed to the screen

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

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions

Question

7. Discuss the key features of the learning organization.

Answered: 1 week ago