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 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).
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):
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....
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  ...
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 ......
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...
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...
Write a complete and syntactically correct Python program to solve the following problem: Write a program...
Write a complete and syntactically correct Python program to solve the following problem: Write a program for your professor that allows him to keep a record of the students’ average grade in his class. The program must be written in accordance with the following specs: 1. The input must be interactive from the keyboard. You will take input for 12 students. 2. You will input the students’ name and an average grade. The student cannot enter an average below zero...
Draw a Flow chart and write a C++ program to solve the quadratic equation ax^2 +...
Draw a Flow chart and write a C++ program to solve the quadratic equation ax^2 + bx + c = 0 where coefficient a is not equal to 0. The equation has two real roots if its discriminator d = b2 – 4ac is greater or equal to zero. The program gets the three coefficients a, b, and c, computes and displays the two real roots (if any). It first gets and tests a value for the coefficient a. if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT