In: Computer Science
Assignment Requirements
Write a python application that consists of two .py files. One file is a module that contains functions used by the main program. NOTE: Please name your module file: asgn4_module.py
The first function that is defined in the module is named is_field_blank and it receives a string and checks to see whether or not it is blank. If so, it returns True, if not it return false.
The second function that is defined in the module is named is_field_a_number and it receives a string and checks to see whether or not it is a number. If so, it returns True, if not it return false.
The other .py file should properly call a main function that does the following...
1. Prompts the user to enter their first name.
Call the is_field_blank function to see if nothing
was entered.
If nothing was entered it displays the following message...
"First Name must be Entered"
...and re-prompts the user to enter the first name. It does this repeatedly until the user enters a first name.
2. Prompts the user to enter their last name.
Call the is_field_blank function to see if nothing
was entered.
If nothing was entered it displays the following message...
"Last Name must be Entered"
...and re-prompts the user to enter the last name. It does this
repeatedly until the user enters a last name.
3. Prompts the user to enter their age.
Call the is_field_blank function to see if nothing
was entered. If nothing was entered it displays the following
message...
"Age must be Entered"
...and re-prompts the user to enter their age. It does this repeatedly until the user enters a age.
Once the user has entered a non-blank age call the
is_field_a_number function to see if the age entered is a number.
If not, display the following message...
"Age must be a Number"
...and re-prompt the user to enter their age. It does this
repeatedly until the user enters a numeric age.
4. If the user's age is over 40 display a message in the following
format:
Well, (first name) (last name) it looks like you are over the hill
Otherwise display a message in the following format:
It looks like you have many programming years ahead of you (first name) (last name)
5. Follow the format of the "Sample Program" below with the first
and last lines appearing as shown. Also, be sure to use line
skipping and spacing the way I show below.
Module Documentation Requirement
You MUST add Python Module Documentation to the the module .py program file
Running a Sample Program
Below is a example of how your program might run if you used the same answers to the prompts I used below. Your program should run in a similar manner... no matter what names (data) are entered.
NOTE: The data I entered appear in maroon bold
Sample Run...
Assignment 4
What is your first name?
First Name must be Entered
What is your first name?
First Name must be Entered
What is your first name? Steve
What is your last name?
Last Name must be Entered
What is your last name? Perry
What is your age?
Age must be Entered
What is your age? ff
Age must be a Number
What is your age? ss
Age must be a Number
What is your age? 55
Well, Steve Perry it looks like you are over the hill
END OF ASSIGNMENT 4
Please find below the code, code screenshots and output screenshots. Please refer to the screenshot of the code to understand the indentation of the code. Please get back to me if you need any change in code. Else please upvote
CODE:
import asgn4_module
print("Assignment 4\n")
fname = "" #Initialize firstname as empty string
while asgn4_module.is_field_blank(fname): #loop untill a non-empty first name is entered
fname = input("What is your first name? ") #Reading the first name
if asgn4_module.is_field_blank(fname): #display error if first name is an empty string
print("First Name must be Entered")
lname = "" #Initialize lastname as empty string
while asgn4_module.is_field_blank(lname): #loop untill a non-empty last name is entered
lname = input("What is your last name? ") #Reading the last name
if asgn4_module.is_field_blank(lname): #display error if last name is an empty string
print("Last Name must be Entered")
age = "" #Initialize age as empty string
#loop untill a non-empty age as number is entered
while asgn4_module.is_field_blank(age) or not asgn4_module.is_field_a_number(age):
age = input("What is your age? ") #Reading the age
if asgn4_module.is_field_blank(age): #display error if age entered is empty
print("Age must be Entered")
else:
if not asgn4_module.is_field_a_number(age): #display error if age is not a number
print("Age must be a Number")
#If the user's age is over 40 display a message in the following format:
#Well, (first name) (last name) it looks like you are over the hill
if int(age) > 40:
print("Well," ,fname, lname, "it looks like you are over the hill")
#Otherwise display a message in the following format:
#It looks like you have many programming years ahead of you (first name) (last name)
else:
print("It looks like you have many programming years ahead of you", fname, lname)
print("END OF ASSIGNMENT 4")
CODE (asgn4_module.py)
#Function to chech wheteher the string is empty or not
def is_field_blank(string):
if string == "":
return True #return true if string is empty
else:
return False #else return false
#Function to check whether the string is a number or not
def is_field_a_number(string):
if string.isdigit():
return True #return True if string is a number
else:
return False #else return false
OUTPUT: