Question

python
Write a progran that reads values from the user until a blank line is entered. Display the total of al1 the values entered by

0 0
Add a comment Improve this question Transcribed image text
Answer #1

"""

    Python program to take input while blank line

    and prints recursive total

"""

# This function takes input recurrsively until it finds blank line and gives total of all numbers

def recursiveUntilBlank():

    inp = raw_input()   # Get the input

    if inp == "":       # If it is a blank line...

        return 0.0

    else:               # recurssive call and add value in previous result

        return float(inp) + recursiveUntilBlank()

# declare main function

def main():

    print(recursiveUntilBlank())    # call and print return value of function

# it calls main function  

if __name__== "__main__":

    main()

blankrec.py - Chegg - Visual Studio Code En * *) 9:09 AM 11 D ... blankrec.py X blankrec.py a AWN Python program to take inpuEn * O *) 9:09 AM viiju@viiju-VPCCW13EGU: -/Documents/Chegg viiju@viiju-VPCCW13EGU:-/Documents/Chegg$ python blankrec.py 0.0

Add a comment
Know the answer?
Add Answer to:
python Write a progran that reads values from the user until a blank line is entered....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Python 3, Write a program that reads a set of floating-point values. Ask the user...

    In Python 3, Write a program that reads a set of floating-point values. Ask the user to enter the values, then print: The number of values entered. The smallest of the values The largest of the values. The average of the values. The range, that is the difference between the smallest and largest values. If no values were entered, the program should display “No values were entered” The program execution should look like (note: the bold values are sample user...

  • Write a program segment that reads 50 numbers entered by the user and display the values...

    Write a program segment that reads 50 numbers entered by the user and display the values overs over, 100. Make sure you declare any variables that are needed.

  • Write a Python program that reads user input from the command-line. The program should define a...

    Write a Python program that reads user input from the command-line. The program should define a function read Position, which reads the values for t, v0, and h0. If there is an IndexError, print 'Please provide the values for t, vO, and hO on the command line.'. If t, v0, or h0 are less than 0. print 't = # is not possible.' for each variable respectively. Note that the # represents the number entered on the command-line by the...

  • Python Write a program which asks the user keep inputting values on a line followed by...

    Python Write a program which asks the user keep inputting values on a line followed by enter until they enter a blank line, at which point the program should print the number of lines entered (excluding the blank).

  • Task 1 Write a Python program that reads in any number of birth years until the...

    Task 1 Write a Python program that reads in any number of birth years until the number zero is entered. The program will then print out the average age and how old the youngest and oldest, respectively. For this task, you can start from the pseudo-code (separately) you received to get started. Example of program execution (user entries in numbers (year)): Enter year of birth. To finish, enter the number 0. Year: 1998 Year: 1932 Year: 1887 Error: Unreasonable year....

  • Write an application in java that accepts any number of String values from a user until...

    Write an application in java that accepts any number of String values from a user until they enter zzz or have entered 15 strings, and display them in ascending order.

  • Write a small JAVA program that continually reads in user values and calculates the average of all values. The program s...

    Write a small JAVA program that continually reads in user values and calculates the average of all values. The program should first ask the user for the number of values to be entered. Upon storing this value, the program should proceed to read in that amount of values. What will be the best strategy here? a suggestion would be only calculating the average after you know you have read in all values. You can expect to use some type of...

  • in python Write a program that reads the date of birth from the user as 3...

    in python Write a program that reads the date of birth from the user as 3 integer values (day, month, year) and then computes and prints their exact age in days. You need to take into account the leap You may not use any built-in functions related to date and time! Example: Someone born on 01/01/2000 is 365 days * 18 years + 5 days (since the years 2000, 2004, 2008, 2012, and 2016 are all leap years) + 352...

  • In this exercise, write a complete Java program that reads integer numbers from the user until...

    In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...

  • MUST BE WRITTEN IN C++ All user input values will be entered by the user from...

    MUST BE WRITTEN IN C++ All user input values will be entered by the user from prompts in the main program. YOU MAY NOT USE GLOBAL VARIABLES in place of sending and returning data to and from the functions. Create a main program to call these 3 functions (5) first function will be a void function it will called from main and will display your name and the assignment, declare constants and use them inside the function; no variables will...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT