0

I'm new to Python and to coding in general. Started learning Python three weeks ago and started learning HTML two days ago.

I made this program. Please don't mind the arbitrary cutoffs for GPA and SAT. This is purely just for practice and not meant as actual college admissions advice.

#New program to guide high school students applying to college

print("Welcome to my college guidance program.")
name=input("To start, please write your name.\n")
name=str(name)

print("Hello",name)

print("Now, tell me what your GPA is.")
GPA=input("What is your unweighted GPA? Round to the nearest hundredth, please.\n")


try:
  GPA=float(GPA)
  if GPA%0.01!=0 or GPA%0.1!=0:
    print("Please round to the nearest hundredth place.")
    #THIS IS WHERE I'M GETTING INTO TROUBLE. I want this to print *only* if the user inputs something like 3 (instead of 3.0) or 2.98943424. Yet, if I write 3.33 or 2.75, this prints anyway. What am I doing wrong?
  if GPA>=3.5 and GPA<=4.0:
    print("You have an excellent GPA.")
  elif GPA>=3.0 and GPA<3.5:
    print("You have a good GPA.")
  elif GPA>=2.0 and GPA<3.0:
    print("Your GPA isn't the best but you should still be able to get into a college somewhere.")
  elif GPA>4.0:
    print("Only your unweighted GPA, please.")
  else:
    print("Your GPA is pretty bad. Fear not, you can still go to community college, and there's nothing wrong with that.")
 #If the user inputs something that's not rounded to the nearest hundredth, I want the program to start over and ask them their GPA again. How can I do that?
except:
  print("Only type in numbers, please.")
finally:
  print("Remember, you are more than just a number!")

 #if the user inputs something other than a number, or something that isn't divisible by 0.01 or 0.1, I want the program to ask again their GPA.

print("Okay! Now, tell me about your SAT score. Only your composite score, not the three individual subsections.")
SAT=input("What is your SAT score?")
try:
  SAT=int(SAT)
except: 
  print("Only numbers, please.")

 #Why does the program stop running here?    

  try:
    if SAT%10!=0:
      print("Remember, the SAT only goes up in increments of 10.") 
      #Same thing as above! I *only* want this to print if the user puts something like 2199. As of right now, if the user writes something like 2199 or anything like that, the program just stops.
    elif SAT>=2100 and SAT<=2400:
      print("That's an excellent score.")
    elif SAT>=1800 and SAT<2100:
      print("That's a good score.")
    elif SAT>=1500 and SAT<1800:
      print("That's a decent score.")
    elif SAT<1500:
      print("The score is a little bit low.")
    

  except:
    print("Only numbers, please.")
    

Thank you so much in advance!

David KT
  • 11
  • 6
  • Please see [this answer](https://stackoverflow.com/a/14763891/3228591). Trying out some modulo operations on floating point numbers in an interactive session will show you that you're not going to get the results you expected. You may want to convert it into an integer (e.g. `GPA = int(float(GPA) * 100)` to do simple truncation, turning 3.452 into 345). Obviously you'd need to multiply the numbers you check against by 100 as well in that case. – Kemp Apr 07 '21 at 10:53
  • This sounds like an XY problem. instead of doing weird stuff with the module operator, you should consider to check for equality with ``3`` and do a type check to make sure it's an ``int``. You could also "abuse" the C-Python internals where "low" integer objects are cached to check for identity with the ``is`` operator: ``GPA is 3`` – Mike Scotty Apr 07 '21 at 10:54

0 Answers0