Advertisement

Responsive Advertisement

Write a program that asks the user how many credits they have taken. If they have taken 23 or less, print that the student is a freshman. If they have taken between 24 and 53, print that they are a sophomore. The range for juniors is 54 to 83, and for seniors it is 84 and over.

 # Ask the user how many credits they have taken

credits = input("Enter the number of credits you have taken: ")


# Check if the input is a valid number

if credits.isdigit():

  credits = int(credits)


  # Print the class year based on the number of credits

  if credits <= 23:

    print("You are a freshman.")

  elif credits <= 53:

    print("You are a sophomore.")

  elif credits <= 83:

    print("You are a junior.")

  else:

    print("You are a senior.")

else:

  print("Invalid input. Please enter a positive integer.")


This program will print the class year of the student based on the number of credits they have taken. For example, if the user enters 12, the program will print You are a freshman., and if the user enters 70, the program will print You are a junior..

The output of the program would depend on what the user enters as input. Here are some example outputs:

Input: 12
Output: You are a freshman.

Input: 30
Output: You are a sophomore.

Input: 70
Output: You are a junior.

Input: 100
Output: You are a senior.

Input: abc
Output:
Invalid input. Please enter a positive integer.

Post a Comment

0 Comments