Write Function Named Calculations Repeatedly Asks User Enter Number User Enters Number 0 Q30234905

InPython, using while loops please! If possible
A. Write a function named calculations() that repeatedly asks the user to enter a number. When the user enters in the number 0, the calculations() function should display the sum of all the numbers entered so far, how many numbers have been entered, the averagell of all the numbers, and the largest number entered. You should not include the last 0 in the calculations. Hint: start by just doing the sum and make sure you can get it to work. Then implement how many numbers have been entered and make sure that works. After that, the average should be easy. And finally, when youve got everything else working, get the maximum value to work. [1 By average, we mean the arithmetic mean. In case you dont remember how to calculate Heres what our version of the looks like when we run it (the black text represents input that the user typed in). Yours doesnt have to look identical to this, but it should be close. For example, your calculations() function needs to say what it wants from the user (including how to stop), and it should state what the values printed at the end represent. Please enter a number (enter 0 when done): Please enter a number (enter 0 when done): 2.5 Please enter a number (enter 0 when done) : Please enter a number (enter 0 when done) : You have entered 3 numbers The sum of all the numbers is 0.5 The average of all the numbers is 0.16666666666666666 The largest number entered is 5.0 Warning: in this rare occasion, we are asking you to write a function that takes no arguments, and returns no value. Instead, your calculations() function needs to display various outputs (using print)) and respond to user input (using input()). 121 f you are stuck, make sure that you understand all the while loop examples in the about while loops, e.g. the Using while Loops Without User Input example, &c. Save your calculations() function in a Python script file named hw06- functions.py B. Improve your calculations function, so that the program doesnt crash if the user immediately enters 0 as the first input. You have to decide for yourself how to handle that situation and what to do when it happens.A. Write a function named calculations() that repeatedly asks the user to enter a number. When the user enters in the number 0, the calculations() function should display the sum of all the numbers entered so far, how many numbers have been entered, the averagell of all the numbers, and the largest number entered. You should not include the last 0 in the calculations. Hint: start by just doing the sum and make sure you can get it to work. Then implement how many numbers have been entered and make sure that works. After that, the average should be easy. And finally, when you’ve got everything else working, get the maximum value to work. [1 By “average, we mean the arithmetic mean. In case you don’t remember how to calculate Here’s what our version of the looks like when we run it (the black text represents input that the user typed in). Yours doesn’t have to look identical to this, but it should be close. For example, your calculations() function needs to say what it wants from the user (including how to stop), and it should state what the values printed at the end represent. Please enter a number (enter 0 when done): Please enter a number (enter 0 when done): 2.5 Please enter a number (enter 0 when done) : Please enter a number (enter 0 when done) : You have entered 3 numbers The sum of all the numbers is 0.5 The average of all the numbers is 0.16666666666666666 The largest number entered is 5.0 Warning: in this rare occasion, we are asking you to write a function that takes no arguments, and returns no value. Instead, your calculations() function needs to display various outputs (using print)) and respond to user input (using input()). 121 f you are stuck, make sure that you understand all the while loop examples in the about while loops, e.g. the Using while Loops Without User Input example, &c. Save your calculations() function in a Python script file named hw06- functions.py B. Improve your calculations function, so that the program doesn’t crash if the user immediately enters 0 as the first input. You have to decide for yourself how to handle that situation and what to do when it happens. Show transcribed image text A. Write a function named calculations() that repeatedly asks the user to enter a number. When the user enters in the number 0, the calculations() function should display the sum of all the numbers entered so far, how many numbers have been entered, the averagell of all the numbers, and the largest number entered. You should not include the last 0 in the calculations. Hint: start by just doing the sum and make sure you can get it to work. Then implement how many numbers have been entered and make sure that works. After that, the average should be easy. And finally, when you’ve got everything else working, get the maximum value to work. [1 By “average, we mean the arithmetic mean. In case you don’t remember how to calculate Here’s what our version of the looks like when we run it (the black text represents input that the user typed in). Yours doesn’t have to look identical to this, but it should be close. For example, your calculations() function needs to say what it wants from the user (including how to stop), and it should state what the values printed at the end represent. Please enter a number (enter 0 when done): Please enter a number (enter 0 when done): 2.5 Please enter a number (enter 0 when done) : Please enter a number (enter 0 when done) : You have entered 3 numbers The sum of all the numbers is 0.5 The average of all the numbers is 0.16666666666666666 The largest number entered is 5.0 Warning: in this rare occasion, we are asking you to write a function that takes no arguments, and returns no value. Instead, your calculations() function needs to display various outputs (using print)) and respond to user input (using input()). 121 f you are stuck, make sure that you understand all the while loop examples in the about while loops, e.g. the Using while Loops Without User Input example, &c. Save your calculations() function in a Python script file named hw06- functions.py B. Improve your calculations function, so that the program doesn’t crash if the user immediately enters 0 as the first input. You have to decide for yourself how to handle that situation and what to do when it happens.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *