Hi, I need help. For my homework I need to create a program in which people can insert numbers and my program will first list all the chosen numbers. Then it is supposed to calculate the sum, average and how many times the number five was chosen. I have been able to do this, as shown with the following coding.
But the second assignment was to change this program, so that the number of inputs can be chosen in the beginning. So the user can chose if they want to input 4 or 6 or whatever amount of numbers they want. And that is where I got stuck, my teacher told me to use loop. Yet I wouldn't know how to. If you now how, will you please help me.
regards, Juru
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#Here the input is organised number1 = input ( 'Please note your 1st number: ' ) number2 = input ( 'Please note your 2nd number: ' ) number3 = input ( 'Please note your 3rd number: ' ) number4 = input ( 'Please note your 4th number: ' ) number5 = input ( 'Please note your 5th number: ' ) number6 = input ( 'Please note your 6th number: ' ) number7 = input ( 'Please note your 7th number: ' ) number8 = input ( 'Please note your 8th number: ' ) #Here the list with all the inputs is formed numberlst = [ int (number1), int (number2) , int (number3), int (number4), int (number5), int (number6), int (number7), int (number8)] print ( 'This is a list of the chosen numbers ' + str (numberlst)) #here the sum is being calculated sum_input = sum (numberlst) print ( 'The sum of the chosen numbers is equal to ' + str (sum_input)) #Then the average is calculated and rounded of average = round ( float (sum_input) / 8 , 1 ) print ( 'The average of the chosen numbers is equal to ' + str (average)) #lastly, the amount of fives is calculated amount_5s = numberlst.count( 5 ) print ( 'You have chosen a total of {} fives' . format (amount_5s)) |
regards, Juru