Python Help!! I have this code for a housing priority calculator and for some reason the math is not being done correctly

Question:

code is supposed to add up and give a star ranking to the user based on thier answers to the prompts i.e first year taking 13 credits, no roommate, no clubs, and has not been in trouble with the law should print 2.5 stars

score = 0

print("Housing Priority Calculator")
print()

print("QUESTION 1")
year = input(" What year are you going into (1, 2, 3, 4): ")

if year == "1":
    score += 0.5
if year == "2":
    score += 0.5
elif year == "3":
    score += 1
elif year == "4":
    score += 1

print("Question 2")
credit = input(" How many credits are you taking: ")

if credit < "12":
    score += 0.5
elif credit >= "12":
    score += 1

print("Question 3")
mate = input("Are you in need of a roommate? (Y/N): ")

if mate == "Y" or "y":
    score += 1
elif mate == "N" or "n":
    score += 0

print("QUESTION 4")
extra = input("are you in any school sponsored extra curricular i.e. sports or clubs? (Y/N)")
if extra == "Y" or "y":
    score += 1
elif extra == "N" or "n":
    score += 0

print("Question 5")
conduct = input("Have you ever been in trouble with the law or school? (Y/N)")
if conduct == "Y" or "y":
    score -1
if conduct == "N" or "n":
    score += 1

print("Your housing priority score is",score,"stars out of 5 stars")

#code is supposed to add up and give a star ranking to the user based on thier answers to the prompts

Asked By: Jannieel

||

Answers:

First: Your or conditions are not properly set

if conduct == "Y" or conduct == "y":
    score += 1

Your first condition is right, but the or "y" is always True. You could also simplify this to conduct.lower() == "y" or use the in operator conduct in ["y", "Y"]

Second: You’re using a less than operator on a string. Change "12" to 12

if int(credit) < 12:
    score += 0.5
elif int(credit) >= 12:
    score += 1
Answered By: solbs

in question 2 you’re comparing strings. do this instead

if int(credit) < 12:
    score += 0.5
elif int(credit) >= 12:
    score += 1
Answered By: 9EED
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.