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
  • 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...

  • 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

  • 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

  • 16.25 LAB 9A: Mad Lib - Loop (program in Python 3) Overview Objective Be able to...

    16.25 LAB 9A: Mad Lib - Loop (program in Python 3) Overview Objective Be able to implement a sentinel-controlled loop. Description Remember from Lab 3C that Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (and hopefully funny) ways. Extend your program from Lab 3C that repeats asking the user for input and displaying the short story until the user wants to quit. Ex: Enter a name:...

  • Write a program in Python that accepts as input an integer N and a real number...

    Write a program in Python that accepts as input an integer N and a real number c, and outputs the coefficient of the Nth degree term of the Taylor series for the function f(x) = ex centered at c. This process should recur until the user enters a quit code. Erroneous input should be excepted as necessary, and should result in a new prompt.

  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

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
ADVERTISEMENT