In: Computer Science
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
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: