Question

In: Computer Science

Directions 1. Start up IDLE3.8 and open a scripting window. 2. Write a program to solve...

Directions

1. Start up IDLE3.8 and open a scripting window.

2. Write a program to solve the following problem:

functions - The program should input 3 integers, do calculations and print results. You need to write 4 functions for average, smallest, largest and middle as well as writing a main(). Use the main() for input, calling functions and output.

Enter a number...6

Enter a number...2

Enter a number...11

Average = 6.33

Smallest = 2

Largest = 11

Numbers in order are 2 6 11

Solutions

Expert Solution

Code:

>>> def average(a,b,c):
   return round((a+b+c)/3,2)#Here we return the average of 3 numbers

>>>def small(a,b,c):
   return min(a,min(b,c))#Here we return the smallest element

>>> def larg(a,b,c):
   return max(a,max(b,c))#Here we return the largest element

>>> def order(a,b,c):
   x=[]
   x.append(a)
   x.append(b)
   x.append(c)#Here we append them into a list
   x.sort()#Then we sort the list
   print("Numbers in order are ",end=" ")
   for i in range(3):#Then we print the elements
       print(x[i],end=" ")

      
>>> def main():
   a=int(input("Enter a number..."))
   b=int(input("Enter a number..."))
   c=int(input("Enter a number..."))
   print("Average =",average(a,b,c))
   print("Smallest =",small(a,b,c))
   print("Largest=",larg(a,b,c))
   order(a,b,c)

Output:

Indentation:


Related Solutions

Write a Java program for slidsender and slidreiver 1. Start the program 2. Get the frame...
Write a Java program for slidsender and slidreiver 1. Start the program 2. Get the frame size from the user 3. To create the frame based on the user 4. To send frames to server from the client 5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal to 6. Stop the program
Write a program to solve the boundary value problem ? ′′ = ? ′ + 2?...
Write a program to solve the boundary value problem ? ′′ = ? ′ + 2? + cos ? for ? ? [0, ?/2] with ?( 0) = 0.3, ?( ?/ 2) = 0.1. Check your numerical solution with actual using necessary plot.(MATLAB)
PLEASE SOLVE I WILL RATE AND THUMBS UP Assembly code question Write an LC3 program to...
PLEASE SOLVE I WILL RATE AND THUMBS UP Assembly code question Write an LC3 program to compute the XOR (exclusive OR) operation. The program computes the XOR of two numbers stored in registers R0 and R1 and returns the result in register R3. To test your program, before computing the XOR load the two values from memory locations x4000 (into R0) and x4001 (into R1).
Directions: 1. Insert the balloon through the open bottom of a modified 2-liter soda bottle and...
Directions: 1. Insert the balloon through the open bottom of a modified 2-liter soda bottle and up over the neck of the bottle. Pull the end of the balloon over the edges of the neck of the bottle. The balloon is held open by the neck of the bottle.     2. Place the plastic bag over the bottom (open) end of the 2-liter bottle and use the rubber band to hold it in place. This will serve as the diaphragm....
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program,...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program, quadroots.m, for finding the roots of the second- order polynomial ax2 + bx + c. Use the quadratic equation. The inputs are the coefficients a,b, and c and the outputs are z1 and z2. The program should produce (exactly) the following output in the Command window when run with (a, b, c) = (1, 2, −3):
Write as a script in the editor window of Matlab: Concession stand. Write a program, ConcessionStand.m,...
Write as a script in the editor window of Matlab: Concession stand. Write a program, ConcessionStand.m, that uses vector-matrix multiplication to tabulate and display the cost of each of the following orders. Assume that a hot dog costs $3.00, a brat costs $3.50, and a Coke costs $2.50. ----------------------------------------------------   hot dogs brats cokes order 1    2 1 3 order 2 1 0 2 order 3 2 2 2 order 4 0 5 1
As a young entrepreneur, you are planning to open a budget hotel with a start-up capital...
As a young entrepreneur, you are planning to open a budget hotel with a start-up capital of RM 350,000. The hotel will have single-bed rooms with an expected rate of RM 90 per room. An average room occupancy rate is about 250 per month. Annual operating expenses for which cover administration, utility and maintenance costs are about RM 80,000. The cash flows will be expected to remain unchanged for the next 10 years. It is expected that the before-tax minimum...
Write a C++ program which prints consecutive dates to the console window starting at January 1,...
Write a C++ program which prints consecutive dates to the console window starting at January 1, 2000, as follows. Saturday, January 1, 2000 Sunday, January 2, 2000 Monday, January 3, 2000 Tuesday, January 4, 2000 ... You will define a function which prints the dates indefinitely, exactly as given above, or prints a specific number of dates. For example, if your function prints 7,581 days the result would look like this. Saturday, January 1, 2000 Sunday, January 2, 2000 ......
Program Requirements: Write a C++ program according to the following requirements: 1.   Open the data file...
Program Requirements: Write a C++ program according to the following requirements: 1.   Open the data file Electricity.txt and read each column into an array (8 arrays total). 2.   Also create 2 arrays for the following: Total Fossil Fuel Energy (sum of all fossil fuels) Total Renewable Energy (sum of all renewable sources) Electricity.txt: Net generation United States all sectors monthly https://www.eia.gov/electricity/data/browser/ Source: U.S. Energy Information Administration All values in thousands of megawatthours Year   all fuels   coal       natural gas   nuclear  ...
Directions: Write a C++ program that will create an array of four integers. It will allow...
Directions: Write a C++ program that will create an array of four integers. It will allow the user to enter in four valid scores and store them in the array. ( valid range is 0 - 100) It will compute the letter grade based upon the four scores, namely, A = 90 - 100, B= 80- 89, C = 70-79, D = 60-69, otherwise F. It will display the scores and letter grade to the screen. NOTE: No menu is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT