Question

In python 3, 1. Write a program that takes a number of credit hours and returns...

In python 3,

1. Write a program that takes a number of credit hours and returns a classification as follows:

29 credits or less: freshman; 30-59 credits: sophomore; 60-89 credits: junior; 90+ credits: senior.

2. Use a loop to valid input such that users can only enter positive numbers.

3. Use a loop to allow the user to keep entering credit hours and receiving classifications until they quit.

All code must be in a function. I suggest the following structure:

returnValidatedInput – gets user input, validates, and returned validated input

printWelcome – tells the user about the program

main – lets the user continue until the quit, calls appropriate helper functions.

Sample run:

Hi and welcome to the undergraduate classification program.

Would you like to continue (Y/N)? Y

Enter the number of credits earned: 94

Classification: Senior

Would you like to continue (Y/N)? Y

Enter the number of credits earned: -80

Invalid input. Enter the number of credits earned: 80

Classification: Junior

Would you like to continue (Y/N)? N

Have a great day!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the answer below:

I have mentioned all the details in the comments.

Please take care of indentation in code, I am attaching an image of the code as well for your reference.

#welcome finction
def printWelcome():
print("Hi and welcome to the undergraduate classification program.")
#get the input from user and return the valid input
def returnValidatedInput():
value = int(input("Enter the number of credits earned: "))
while(value < 0):
print("Invalid input.")
value = int(input("Enter the number of credits earned: "))
return value

#classification of value
def classification(value):
if(value<=29):
return "Freshman"
if(value<=59):
return "Sophomore"
if(value<=89):
return "Junior"
return "Senior"

#main function to ask user until user want
def main():
#call welcome
printWelcome()
#get intial input from user
user_in = input("Would you like to continue (Y/N)? ")
#loop till user says yes
while(user_in == 'Y'):
#get value from user
value = returnValidatedInput()
#classify value and print result
print("Classification: " ,classification(value))
#check if user wants to continue
user_in = input("Would you like to continue (Y/N)? ")
#goodbye message
print("Have a great day!")
  
#call to main function
main()

Code:

Output:

Add a comment
Know the answer?
Add Answer to:
In python 3, 1. Write a program that takes a number of credit hours and returns...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The function below takes one non-negative numeric parameter: (credit_hours_earned) containing the number of credit hours that...

    The function below takes one non-negative numeric parameter: (credit_hours_earned) containing the number of credit hours that a student earned. Complete the function to return a string indicating the student's classification as indicated by the table below. For example, for 36 credit hours, your function should return 'Sophomore standing'. (python) Freshman standing = 0–29.9 hours Sophomore standing = 30–59.9 hours Junior standing = 60–89.9 hours Senior standing = 90 or more hours Function: def determine_standing(credit_hours_earned):

  • in Python: Write a program that allows the user to enter a number between 1-5 and...

    in Python: Write a program that allows the user to enter a number between 1-5 and returns an animal fact based on what the user entered. The program should 1. Continue to run until the user enters “quit” to terminate the program, and 2. Validate the user’s input (the only acceptable input is 1, 2, 3, 4, 5 or “quit”). You can use the following animal facts: An octopus is a highly intelligent invertebrate and a master of disguise. Elephants...

  • Please help me with this Python program. Write a program that takes the plastic identification number...

    Please help me with this Python program. Write a program that takes the plastic identification number from the user and returns information. The program should allow the user to continue using the program until they quit. It should also validate the input and only accept the integers 1-7 as input. All code should be in a function. I suggest the following function structure: printWelcome - prints program information validateUserinput1 to7 - takes user input, validates, and returns valid input main...

  • This program will implement a simple guessing game... Write a program that will generate a random...

    This program will implement a simple guessing game... Write a program that will generate a random number between 1 and 50 and then have the user guess the number. The program should tell the user whether they have guessed too high or too low and allow them to continue to guess until they get the number or enter a 0 to quit. When they guess the number it should tell them how many guesses it took. At the end, the...

  • PYTHON Write a program to enter a valid variable till the user wants to end. The...

    PYTHON Write a program to enter a valid variable till the user wants to end. The program should display the count of positive, negative, zeros and letters (upper and lower case)/symbols (error handling) entered. Based on the problem, you need to design an algorithm as follows: 1. Get the user input until “n” is entered 2. Add to the positive if it is greater than zero 3. Add to the negative if it is less than zero 4. Add to...

  • Write a program that prompts the user to enter two characters and displays the major and status represented in the characters.

    Write a program that prompts the user to enter two characters and displays the major and status represented in the characters. The first character indicates the major and the second is number character 1, 2, 3, 4, which indicates whether a student is a freshman, sophomore, junior, or senior. Suppose the following characters are used to denote the majors: M: MathematicsC: Computer Science T: Testing and Certification

  • python program 6 Write an input validation loop that asks the user to enter a number...

    python program 6 Write an input validation loop that asks the user to enter a number in the range of 100 through 1000? 7 Write an input validation loop that asks the user to enter ‘Y’, ‘y’, ‘N’, or ‘n’? 8 How many times the following loop will repeat? cnt = 0    while  cnt != 5: print(cnt) cnt = cnt + 2

  • Time Displacement (12-hour format) Write a program that requests the current time and a waiting time...

    Time Displacement (12-hour format) Write a program that requests the current time and a waiting time as two integers for the number of hours and the number of minutes to wait. The program then outputs what the time will be after the waiting period. Use 24-hour notation for the input time and 12-hour notation for the output time. Include a loop that lets the user repeat this calculation for additional input values until the user says she or he wants...

  • Write a PYTHON program that allows the user to navigate the lines of text in a...

    Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...

  • In Python, write a program that asks the user for a positive integer number. If the...

    In Python, write a program that asks the user for a positive integer number. If the user enters anything else, the program would ask the user to re-enter a number or enter -1 to quit. If it is a positive number, the program then prints out a multiplication table that goes up to that number. For example, if the user enters 10, the output would look something like this. https://www.vectorstock.com/royalty-free-vector/multiplication-table-on-white-background-vector-2721686

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT