this chapter, you learned how to write your own, useful functions. Your functions can receive input data and produce output data. With this new ability, you should be able to write programs that are more flexible and powerful with little effort!

To demonstrate a useful function, you are going to complete the "Verification" program. The program should contain a function called get_verified_integer() that will prompt the user for an integer and follow typical input verification steps to produce a valid integer result.

Program Overview
The main program itself will use the get_verified_integer() program to gather three pieces of data from the user (a month, day, and year). The data will then be combined to tell the user the day of the week for that particular date. You've done similar date/time operations before, so we'll give you some starter code to handle that part of the program. You can focus on just writing a useful function that verifies user input.

The main idea of this activity is to demonstrate how you can create useful functions that may apply to many different situations. As you write additional programs on your own, you can create functions like get_verified_integer() that can be called to handle common tasks. Use input parameters to guide the behavior of the function and to produce the desired output.
The following sample run demonstrates how the program should work. Any date can be entered (including today's date or a date known to you) and the correct day of the week should be displayed. We use May 13, 2018 as a sample date (this is Mother's Day in the U.S., a Sunday).

Please enter today's month (1-12): one
Try again - Please enter today's month (1-12): 0
Try again - Please enter today's month (1-12): 5
Please enter today's day (1-31): two
Try again - Please enter today's day (1-31): 32
Try again - Please enter today's day (1-31): 13
Please enter today's year (2000 - 2030): 2018
Today is a Sunday
If incorrect input is received, the program should re-prompt the user with "Try again - " on the front of the message until correct input is entered. The input must be an integer in the specified range.

Your program only needs to validate that each input falls within the range. It will still be possible to enter dates that don't exist on a real calendar like February 31st (2/31) or April 31st (4/31), and these invalid dates can cause an error. That's OK, we are not asking you to validate the entire date, just the individual parts.
Starting Code
The main program is provided for you in the "Verification" starter code. However, the get_verified_integer() function itself is missing. It will be your task to create this entire function and make sure it works correctly.

If you are working offline, you can copy and paste this code into a "Verification.py" source file that you create. But if you are working with CompuScholar's auto-graded system, you will find this code waiting for you when you click on the activity link in the course interface.

# Student name

import datetime

# Define the get_verified_integer function

# main program starts here
month = get_verified_integer("Please enter today's month (1-12): ",1,12)
day = get_verified_integer("Please enter today's day (1-31): ",1,31)
year = get_verified_integer("Please enter today's year (2000 - 2030): ",2000,2030)

# build date object and print out the day of the week
today = datetime.date(year,month,day)
print("Today is a " + today.strftime("%A"))
Copy
Detailed Program Requirements
You do not need to change any of the main program. Simply create the get_verified_integer() function that meets the following requirements:

Locate the get_verified_integer() function above the main program code, where shown in the starter code comments.
The function must accept three input parameters called prompt, min and max in that order.
prompt will contain the message that will be displayed to the user for this particular input
min will contain the minimum acceptable integer value
max will contain the maximum acceptable integer value
The function must loop until valid input is received.
On each loop, use input() and the prompt to get a string from the user.
Convert the string to an integer and verify that it is between the min and max values.
Use try / except to catch any exceptions when non-integer strings are entered.
Return the valid input from the function as soon as it is verified.
Each time the verification fails for any reason, print "Try again - " but do not change to the next line. This means the next prompt will be displayed on the same line after "Try again - " as shown in the program demonstration.
Hint: Remember, to print() a message and stay on the same line, you can set the named parameter "end" equal to a space or empty string (""). Review Chapter 3, Lesson 1 for details.
We are not going to guide you line-by-line through the creation of the get_verified_integer() function. You have seen very similar verification code in the past and should be confident that you can write your own logic based on a set of requirements. You can select your own local variable names inside the function and write your own logic for input prompting, looping, exception handling, and range verification. It's the results that count!
Activity Results
The following example runs demonstrate some known dates and resulting output. You can use these dates to test your program. Be sure to also carefully test the input verification logic and ensure the program retries with correct prompting until valid input is received.

Test #1: 2018-01-01 is a Monday
Please enter today's month (1-12): 1
Please enter today's day (1-31): 1
Please enter today's year (2000 - 2030): 2018
Today is a Monday
Test #2: 2019-12-31 is a Tuesday
Please enter today's month (1-12): 12
Please enter today's day (1-31): 31
Please enter today's year (2000 - 2030): 2019
Today is a Tuesday
Test #3: 2000-01-01 is a Saturday
Please enter today's month (1-12): 1
Please enter today's day (1-31): 1
Please enter today's year (2000 - 2030): 2000
Today is a Saturday
Test #4: 2030-12-31 is a Tuesday. Validation and retry logic should work for all three values
Please enter today's month (1-12): twelve
Try again - Please enter today's month (1-12): 13
Try again - Please enter today's month (1-12): 12
Please enter today's day (1-31): zero
Try again - Please enter today's day (1-31): 0
Try again - Please enter today's day (1-31): 31
Please enter today's year (2000 - 2030): oops
Try again - Please enter today's year (2000 - 2030): 1999
Try again - Please enter today's year (2000 - 2030): 2031
Try again - Please enter today's year (2000 - 2030): 2030
Today is a Tuesday
Of course, you can also test with other known dates, including today's date. When your program is complete and tested, submit it for grading.

Remember, we will not test your program with invalid dates that don't exist on a real calendar.


Activity Rubric
If your project is being automatically graded by our system, your grade will be calculated from 0 to 100 as follows:

Points Description
20 get_verified_integer() function defined
20 get_verified_integer() function requires correct parameters
12 Testing mystery date #1
12 Testing mystery date #2
12 Testing mystery date #3
12 Testing mystery date #4
12 Testing input validation and "Try again" prompts

# Student name

import datetime

# Define the get_verified_integer function

# main program starts here
month = get_verified_integer("Please enter today's month (1-12): ",1,12)
day = get_verified_integer("Please enter today's day (1-31): ",1,31)
year = get_verified_integer("Please enter today's year (2000 - 2030): ",2000,2030)

# build date object and print out the day of the week
today = datetime.date(year,month,day)
print("Today is a " + today.strftime("%A"))

# Student name

import datetime

def get_verified_integer(prompt, min, max):
while True:
try:
user_input = int(input(prompt))
if user_input >= min and user_input <= max:
return user_input
else:
print("Try again - ", end="")
except ValueError:
print("Try again - ", end="")

# main program starts here
month = get_verified_integer("Please enter today's month (1-12): ", 1, 12)
day = get_verified_integer("Please enter today's day (1-31): ", 1, 31)
year = get_verified_integer("Please enter today's year (2000 - 2030): ", 2000, 2030)

# build date object and print out the day of the week
today = datetime.date(year, month, day)
print("Today is a " + today.strftime("%A"))