| 1. |
I need answer of this question: Write a program that reads values from the user until a blank line is entered. Display the total of all of the values entered by the user (or 0.0 if the first value entered is a blank line). Complete this task using recursion. Your program may not use any loops. in python programming lenguage |
|
Answer» Program: def fun(): N = input("If you WANT to exit enter a blank line otherwise enter a value : ") if n == "": return 0.0 else: n = int(n) return (n + fun()) print("Total of all the VALUES = ", fun()) Output 1: If you want to exit enter a blank line otherwise enter a value : 1 If you want to exit enter a blank line otherwise enter a value : 2 If you want to exit enter a blank line otherwise enter a value : 3 If you want to exit enter a blank line otherwise enter a value : 4 If you want to exit enter a blank line otherwise enter a value : Total of all the values = 10.0 Output 2: If you want to exit enter a blank line otherwise enter a value : Total of all the values = 0.0 |
|