Homework Help: Questions and Answers: Part A: Write a Python program that Asks the user to input their name and stores it in an appropriately typed variable. Input prompt should be clear and explain what the user should enter
Part B: Write a Python program that (assume for this program that student gets in state tuition and is on the Macon campus):
1. Greets the user with the name entered for Part A.
2. Asks the user to input how many credit hours they are registered for at MGA and stores it in an appropriately typed variable.
3. Input prompt should be clear and explain what the user should enter.
4. Calculates the amount of tuition based on the credit hours registered ($174 per credit hour).
5. Displays the additional fees ($45 activity fee, $45 athletic fee, $20 health fee, $10 parking fee, $180 Rec and Wellness fee and $46 technology fee) which should be stored in a tuple.
6. Displays the amount of tuition calculated in step 2.
7. Displays the total for the semester (step 2 + step 4).
8. Outputs should clearly label what is being displayed.
Answer:
Lets solve this problem step by step, creating two separate Python programs as per question. Let’s start with Part A:
Part A: Python Program for User Input
Objective: Write a program that asks the user for their name and stores it in a variable.
Steps:
- Use the
input()
function to ask the user to enter their name. - Store the input in a string variable, since the name is textual data.
Code for Part A:
# Part A: Get the user's name name = input("Please enter your name: ")
Part B: Python Program for Tuition Calculation
Objective: Extend the program to greet the user, calculate tuition based on the number of credit hours, and display additional fees.
Step by Step Programing:
- Greet the user using the name from Part A.
- Ask the user to input the number of credit hours they are registered for and store it as an integer.
- Calculate the tuition by multiplying the credit hours by $174 (cost per credit hour).
- Define the additional fees in a tuple.
- Display the tuition and the additional fees.
- Calculate the total amount by adding the tuition and the sum of the additional fees.
- Display the total amount.
Code for Part B:
# Part B: Tuition and Fees Calculation
# 1: Greet the user
print(f"Hello, {name}!")
# 2: Ask for the number of credit hours
credit_hours = int(input("Please enter the number of credit hours you are registered for: "))
# 3: Calculate the tuition
tuition_per_credit_hour = 174
tuition = credit_hours * tuition_per_credit_hour
# 4: Define the additional fees in a tuple
fees = (
("Activity fee", 45),
("Athletic fee", 45),
("Health fee", 20),
("Parking fee", 10),
("Rec and Wellness fee", 180),
("Technology fee", 46)
)
# 5: Display the calculated tuition
print(f"Tuition for {credit_hours} credit hours: ${tuition}")
# 6: Display the additional fees
print("Additional fees:")
total_fees = 0
for fee_name, fee_amount in fees:
print(f"{fee_name}: ${fee_amount}")
total_fees += fee_amount
# 7: Calculate and display the total amount
total_for_semester = tuition + total_fees
print(f"Total for the semester: ${total_for_semester}")
Conclusion:
Part A: The user is prompted to enter their name, which is stored and used later.
Part B: The user is greeted, asked for their registered credit hours, and then the program calculates the tuition, displays the additional fees, and finally calculates and displays the total amount for the semester.
This program is complete, ensuring clarity and proper labeling of inputs and outputs.
Learn More: Homework Help
Q. The topics in the Content area are set up at the discretion of your instructor?