Is my code correct | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is my code correct

def my_greatest(numbers): print("The average of the three numbers is:", numbers) total_sum=0 for my_numbers in range(3): my_numbers=("Enter a number: ") avg=my_numbers my_greatest(numbers) We were asked to define a function my_greatest, prompt a user to enter 3 numbers and all three numbers a passed to the function, and the function must calculate the average of the 3 values is my code correct please help.

27th Mar 2020, 9:51 PM
Michael Bafana
2 Answers
+ 5
To be honest, this code is not doing what want to achieve. You should start by doing these steps: - write code for input the required data. you have done this by using a for loop, but there is an input() missing, and you have to put the three input values in a list. The input has to be a numerical data type. - write the function, that should calculate the average of the 3 values. this function needs to accept a list of values. Count the number of values / elements in the list. build the sum of all the numbers in the list. then divide the sum by the number of elements. this is the result of the calculation. - depending who should output the result. if function should print the result, create code for this output. if main program should print the result, the function has to return the calculated value to the main program. print output there. - write the code that calls the function by passing the list of values as an ragument.
28th Mar 2020, 11:18 AM
Lothar
Lothar - avatar
0
Please help
27th Mar 2020, 10:45 PM
Michael Bafana