0

Please help me with my code

Write a Python program that will ask the user to choose between A or B. If A is chosen the program will compute and display the Harmonic Mean of a given series of numbers else it will compute and display the Geometric Mean. Let 0 be the sentinel value. Harmonic and Geometric means are define below. Use the following user-defined functions in your program: validate_choice() – choice must be A/a or A/b only display_menu()-display menu and allow user to choose between A and B validate_n() – validate n, n>0 harmonic() – input series of numbers and compute harmonic mean geometric() – input series of numbers and compute geometric mean display_mean()-display harmonic or geometric mean Note: Input validation : for choice A/B, if input is invalid, ask again until a valid data is given, program must accept uppercase or lowercase character Input validation : in Geometric Mean, do not accept if number is less than 0 Round-off results to 4 decimal places Program should execute for as long as the user wants to continue Provide 2 sample runs using the test data below: Test Data 1 : if A : 9, 2, 3.6, -5.4, 4.6, 0.8, 9.7, -2.3, -1.4, 0 Test Data 2 : if B : 7, 4, 3.6, -5.4, -4.6, 4.6, 0.8, 9.7, -2.3, -1.4, 1.4, 0 https://code.sololearn.com/cAkcyxvsUGyZ/?ref=app

1st Apr 2020, 3:12 AM
denise
2 Answers
+ 1
I made an improved version of your program, I hope it works as you think it should: https://code.sololearn.com/c0JhAW0Hfvv1/?ref=app
2nd Apr 2020, 5:42 PM
Paul
Paul - avatar
0
Hello dear friend! For me after checking on your code i figured out that it is requring (7 inputs) That's why it is returning a traceback file error. An idea i may give is that you may give i suggest that it gave two inputs which are: 1.the choice of A/a or B/b. 2. The second is where you state the terms of the series. After here its where you may now write every function that is only iterating according to these two inputs. Where you say. Eg: if choice=A or choice= a: ....... then here it is where you will write all other conditions regarding the choice of A/a.. The last statement will be an else statement where if the input is different. From a or b there will be no output but print a statement showing the use that he /she shall choose between a or b
2nd Apr 2020, 12:43 AM
Josaphat NGOGA UWIZEYE
Josaphat NGOGA UWIZEYE - avatar