Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Separate function to calculate the grade
- def calculate_grade(student_score):
- if student_score >= 60:
- if student_score < 70:
- return "D"
- elif student_score < 80:
- return "C"
- elif student_score < 90:
- return "B"
- else:
- return "A"
- else:
- return "F"
- # Separate function to get student information
- def get_student_info():
- student_name = input("Enter student name (or type 'exit' to quit): ")
- if student_name.lower() == 'exit':
- return None, None
- student_score = int(input("Enter student score: "))
- return student_name, student_score
- # Separate function to display the grade
- def display_grade(student_name, student_score, student_grade):
- print(f"Student {student_name} scored {student_score} and received a grade of {student_grade}.")
- # Main program
- def main():
- print("Welcome to the Student Grade Calculator!")
- while True:
- student_name, student_score = get_student_info()
- if student_name is None:
- print("Goodbye!")
- break
- student_grade = calculate_grade(student_score)
- display_grade(student_name, student_score, student_grade)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement