Question

In: Computer Science

Assignment Requirements Write a python application that consists of two .py files. One file is a...

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

Solutions

Expert Solution

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:


Related Solutions

Write a Python program stored in a file q3.py that: Gets single-digit numbers from the user...
Write a Python program stored in a file q3.py that: Gets single-digit numbers from the user on one line (digits are separated by white space) and adds them to a list. The first digit and the last digit should not be a zero. If the user provides an invalid entry, the program should prompt for a new value. Converts every entry in the list to an integer and prints the list. The digits in the list represent a non-negative integer....
C# Simple Text File Merging Application - The idea is to merge two text files located...
C# Simple Text File Merging Application - The idea is to merge two text files located in the same folder to create a new txt file (also in the same folder). I have the idea, and I can merge the two txt files together, however I would like to have an empty line between the two files. How would I implement this in the code below? if (File.Exists(fileNameWithPath1)) { try { string[] file1 = File.ReadAllLines(fileNameWithPath1); string[] file2 = File.ReadAllLines(fileNameWithPath2); //dump...
PYTHON Computer Science Objectives Work with lists Work with functions Work with files Assignment Write each...
PYTHON Computer Science Objectives Work with lists Work with functions Work with files Assignment Write each of the following functions. The function header must be implemented exactly as specified. Write a main function that tests each of your functions. Specifics In the main function ask for a filename and fill a list with the values from the file. Each file should have one numeric value per line. This has been done numerous times in class. You can create the data...
Need this program Using Classes , Objects, Save to file, and Printbill Simple python assignment Write...
Need this program Using Classes , Objects, Save to file, and Printbill Simple python assignment Write a menu-driven program for Food Court. (You need to use functions!) Display the food menu to a user (Just show the 5 options' names and prices - No need to show the Combos or the details!) Ask the user what he/she wants and how many of it. (Check the user inputs) AND Use strip() function to strip your inputs. Keep asking the user until...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two output tiles. One file listing out all boys names, and the other file listing out all girls name. CODE: (teacher gave some of the code below use it to find the answer please String B is the boy names String E is girl names) import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program reads a file with numbers, and writes the numbers...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two output tiles. One file listing out all boys names, and the other file listing out all girls name. CODE: (teacher gave some of the code below use it to find the answer please String B is the boy names String E is girl names) import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program reads a file with numbers, and writes the numbers...
In Python This assignment involves the use of text files, lists, and exception handling and is...
In Python This assignment involves the use of text files, lists, and exception handling and is a continuation of the baby file assignment. You should now have two files … one called boynames2014.txt and one called girlnames2014.txt - each containing the top 100 names for each gender from 2014. Write a program which allows the user to search your files for a boy or girl name and display where that name ranked in 2014. For example … >>>   Enter gender...
What to do: 1. Write a Python program, a1.py with the following characteristics: a) there are...
What to do: 1. Write a Python program, a1.py with the following characteristics: a) there are at least 40 lines of comments and 40 lines of code (1 point) b) the problem is described at the top of the program in a readable fashion (1 point) c) the code includes at least one instance of each of the five learning objectives listed above. (3 points) d) the code solves the problem. This may be assessed in part by a 'code...
What to do: 1. Write a Python program, a1.py with the following characteristics: a) there are...
What to do: 1. Write a Python program, a1.py with the following characteristics: a) there are at least 40 lines of comments and 40 lines of code (1 point) b) the problem is described at the top of the program in a readable fashion (1 point) c) the code includes at least one instance of each of the five learning objectives listed above. (3 points) d) the code solves the problem. This may be assessed in part by a 'code...
Write a python program: There is a file called file 2. File2 is a txt file...
Write a python program: There is a file called file 2. File2 is a txt file and I have written the contents of file 2 below in the exact format it was in notepad. # This comment does not make sense # It is just to make it harder # The job description starts after this comment, notice that it has 4 lines. # This job description has 700150 hay system points\\ the incumbent will administer the spending of kindergarden...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT