Look carefully at the code for your functions read_age and read_siblings. Can you see a pattern? Each of these functions prompts the user until they supply a valid integer, which is then returned. In fact, the only differences between the two function are the prompt string for the user and a few variable names. When we find very similar blocks of code like this in a program, we should look for a single function that can do both tasks. So ... how can we generalis these functions into a single function that can be used (in two separate calls) to read both the age and the number of siblings while still printing a suital prompt? Add a new function to your program called read_int (prompt) that takes a prompt string as input. It should use that string to prompt the user for a valid integer and then return it. Once you have done this, delete the functions read_age and read_siblings from your program and replace all calls to them with appropriate calls to yo new read_int(prompt) function so that your main function looks something like this: def main(): ""This function runs the show"" name = input ("What is your name? ") age = read_int("How old are you? ") num_siblings = read_int ("How many siblings do you have? ") print_info(name, age, num_siblings) Before submitting your answer, test it in Wing to make sure that your program still behaves exactly the same as it did before. Notes: • Your answer is not allowed to use or include the functions read_age and read_siblings. • No function in your program is allowed to be longer than 10 statements. Be sure to paste the entire program in the answer box. For example: Test Input Result Angus What is your name? Angus How old are you? 19 # This test simply runs your program, # so make sure you include your call to main() 19 How many siblings do you have? 3 Hi Angus. Next year you will be 20 years old. 3 You have 3 siblings.
Look carefully at the code for your functions read_age and read_siblings. Can you see a pattern? Each of these functions prompts the user until they supply a valid integer, which is then returned. In fact, the only differences between the two function are the prompt string for the user and a few variable names. When we find very similar blocks of code like this in a program, we should look for a single function that can do both tasks. So ... how can we generalis these functions into a single function that can be used (in two separate calls) to read both the age and the number of siblings while still printing a suital prompt? Add a new function to your program called read_int (prompt) that takes a prompt string as input. It should use that string to prompt the user for a valid integer and then return it. Once you have done this, delete the functions read_age and read_siblings from your program and replace all calls to them with appropriate calls to yo new read_int(prompt) function so that your main function looks something like this: def main(): ""This function runs the show"" name = input ("What is your name? ") age = read_int("How old are you? ") num_siblings = read_int ("How many siblings do you have? ") print_info(name, age, num_siblings) Before submitting your answer, test it in Wing to make sure that your program still behaves exactly the same as it did before. Notes: • Your answer is not allowed to use or include the functions read_age and read_siblings. • No function in your program is allowed to be longer than 10 statements. Be sure to paste the entire program in the answer box. For example: Test Input Result Angus What is your name? Angus How old are you? 19 # This test simply runs your program, # so make sure you include your call to main() 19 How many siblings do you have? 3 Hi Angus. Next year you will be 20 years old. 3 You have 3 siblings.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question

Transcribed Image Text:Look carefully at the code for your functions read_age and read_siblings. Can you see a pattern?
Each of these functions prompts the user until they supply a valid integer, which is then returned. In fact, the only differences between the two functions
are the prompt string for the user and a few variable names.
When we find very similar blocks of code like this in a program, we should look for a single function that can do both tasks. So ... how can we generalise
these functions into a single function that can be used (in two separate calls) to read both the age and the number of siblings while still printing a suitab
prompt?
Add a new function to your program called read_int(prompt) that takes a prompt string as input. It should use that string to prompt the user for a valid
integer and then return it.
Once you have done this, delete the functions read_age and read_siblings from your program and replace all calls to them with appropriate calls to you
new read_int(prompt) function so that your main function looks something like this:
def main():
""This function runs the show"""
name = input("What is your name? ")
age = read_int("How old are you? ")
num_siblings = read_int("How many siblings do you have? ")
print_info(name, age, num_siblings)
Before submitting your answer, test it in Wing to make sure that your program still behaves exactly the same as it did before.
Notes:
• Your answer is not allowed to use or include the functions read_age and read_siblings.
• No function in your program is allowed to be longer than 10 statements.
• Be sure to paste the entire program in the answer box.
For example:
Test
Input Result
# This test simply runs your program,
Angus What is your name? Angus
# so make sure you include your call to main()
19
How old are you? 19
How many siblings do you have? 3
Hi Angus. Next year you will be 20 years old.
You have 3 siblings.
3
# Testing your read_int function only
# Here we ignore the call to main()
num = read_int("What's your favourite number? ")
print (f"I like {num} too.")
dunno What's your favourite number? dunno
seven Please enter an integer.
What's your favourite number? seven
Please enter an integer.
7
What's your favourite number? 7
I like 7 t0o.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education