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

Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file must satisfy the following. Define a function named rinsert. This function will accept two arguments, the first a list of items to be sorted and the second an integer value in the range 0 to the length of the list, minus 1. This function shall insert the element corresponding to the second parameter into the presumably sorted list from position 0 to one less...
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...
File Compare Write a program that opens two text files and reads their contents into two...
File Compare Write a program that opens two text files and reads their contents into two separate queues. The program should then determine whether the files are identical by comparing the characters in the queues. When two nonidentical characters are encountered, the program should display a message indicating that the files are not the same. If both queues contain the same set of characters, a message should be displayed indicating that the files are identical. // Copyright (c) 2013 __Pearson...
This needs to be written in JavaScript with two files. One HTML file and a JavaScript...
This needs to be written in JavaScript with two files. One HTML file and a JavaScript file. Make an empty HTML file, put three buttons inside the body and an empty main tag below the buttons. The text of the buttons should be "Foo", "Bar", and "FooBar" respectively. Don't put the " in the buttons that's just for clarification in these instructions. Add unique IDs to each button In your JavaScript, get 3 separate references to the buttons using the...
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...
a python function that reads two text files and merges in to one Linked List, be...
a python function that reads two text files and merges in to one Linked List, be able to print each Item in the new single Linked List class Node(object): item = -1 next = None def __init__(self, item, next): self.item = item self.next = next ================================ textfile! 979 2744 5409 1364 4948 4994 5089 703 1994 4637 2228 4004 1088 2812 170 5179 2614 238 4523 4849 3592 3258 1951 3440 3977 1247 4076 1824 4759 4855 5430 347 974...
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT