Question

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. Try again.
Year: 1987
Year: -77
Error: Unreasonable year. Try again.
Year: 1963
Year: 0
The average age is 49 years. The youngest is 21 years old and the oldest is 87 years old.

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

NOTE : I did not get any pseudo code as such. I am writing the code with my logic. Please consider it.

In my code i am accepting the lowest year 1915. I do not know what is the lowest year you have considered in your code.

Code in python3 :

lowest = 115
highest = -100
average = 0
total = 0
entries = 0
print("Enter year of birth. To finish, enter 0")
while True:
print("Year: ")
val = input()
if (int(val) == 0):
break;
if ((int(val) >= 1915)and(int(val)<=2019)):
temp = 2019-int(val)
if (temp < lowest):
lowest = temp
if (temp > highest):
highest = temp
total = total + temp
entries = entries + 1
else:
print("Unreasonable year. Try again")
average = float(total)/entries
print("The average age is ",average,end=".")
print("The youngest is ",lowest," years old and the oldest is ",highest," years old")

Screen shots of written code :


  
PLEASE GIVE THUMBS UP.

  

Add a comment
Know the answer?
Add Answer to:
Task 1 Write a Python program that reads in any number of birth years until the...
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 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...

  • task The cutoff birth date for school entry in British Columbia, Canada, is December 31. As...

    task The cutoff birth date for school entry in British Columbia, Canada, is December 31. As a result, children bom in December tend to be the youngest in their grade, whereas those bom in January tend to be the oldest. Morrow et al. (2012) examined how this relative age difference influenced diagnosis and treatment of attention deficit/hyperactivity disorder (ADHD). A total of 39,136 boys aged 6 to 12 years and registered in school in 1997– 1998 had January birth dates....

  • Python Programming Write a program that reads the dimension of a rectangle and prints its area....

    Python Programming Write a program that reads the dimension of a rectangle and prints its area. The program must handle errors such invalid input. If it encounters an error, it should ask the user to reenter the input. Sample run: Enter height:abc abc is not a vaid input. Try again. Enter height:10 Enter width:hello hello is not a vaid input. Try again. Enter width:world world is not a vaid input. Try again. Enter width:xyz xyz is not a vaid input....

  • 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...

  • [JAVA} Thanks in advance for your help! Write a program that asks the user to type...

    [JAVA} Thanks in advance for your help! Write a program that asks the user to type in ages. They will type a negative age when they finish entering the ages. The program will print out the average of all of the ages and the oldest age entered. It should end with a newline. Sample output #1 Type a negative for age to exit Enter your age: 21 Enter your age: 22 Enter your age: 21 Enter your age: -8 The...

  • 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...

  • Write in python code Project 11-1: Birthday Calculator Create a program that accepts a name and...

    Write in python code Project 11-1: Birthday Calculator Create a program that accepts a name and a birth date and displays the person's birthday the current day, the person's age, and the number of days until the person's next birthday Console Birthday Calculator Enter name: Joel Enter birthday (MM/DD/YY): 2/4/68 Birthday: Sunday, February 04, 1968 Today: Joel is 48 years old. Joel's birthday is in 73 days Tuesday, November 22, 2016 Continue? (y/n): y Enter name: Django Enter birthday (MM/DD/YY):...

  • Write a program called RentalRate.java which reads in a date of birth, today’s date and a...

    Write a program called RentalRate.java which reads in a date of birth, today’s date and a male/female designation from the user, and will then determine the basic daily and weekly rates for rental of an economy class car. Rental rate classes are: Best rate (male drivers, age 33–65 and female drivers, age 30-62)--$40.00per day, $200.00 per week Risk rate 1 (female drivers, age 25–29)–Best rate plus $10.00 per day or best rate plus $55.00 per week. Risk rate 2 (male...

  • Problem Definition Write a program called process_ages that reads in an array of up to 10...

    Problem Definition Write a program called process_ages that reads in an array of up to 10 integers representing peoples ages in years and calculates and prints the maximum age and the minimum age and the average age. Your program should stop reading when either the 10th number is entered or the user enters -1. If the user enters any other negative number or a value above 150, they should be warned and prompted again for a valid age. You should...

  • 5. The Success Academy is organizing an event for its students. Write a Python program that...

    5. The Success Academy is organizing an event for its students. Write a Python program that prompts the user to enter the student's age and gender. The program should then display the day and time for the event registration based on the table below: Gender Registration Monday, 10:00am- 12:00pm Tuesday, 9:00am-12:00pm Wednesday, 9:00am-12:00pm Age Below 10 years old 10 years old and above Male Female Write a Python program that prompts the user to enter his/her monthly weight for the...

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
Active Questions
ADVERTISEMENT