0

I am having syntax errors on the below code and can't determine why. Additionally, if I comment out the elif statements, my line 12 does not actually add the variables together.

#Define variables and collect inputs
points =  int(input("How many points do you have?:  "))
years =  int(input("How many years have you been a customer?:  "))

points_discount = float()

years_discount = float()

final_discount = float()

#formula for additional discount
final_discount = points_discount + years_discount

#if statements for the points
if points <= 50:
    points_discount == 0.00
elif points > 50 and <= 100:  # SyntaxError here.
    points_discount == 0.10
elif points >100 and <=200:
    points_discount == 0.20
elif points >200 and <=300
    points_discount ==  0.25
else:
    points_discount == 0.30

#if statement for the years as a customer
if years < 5:
    years_discount  == 0.00
else:
    years_discount == 0.05

print(str(final_discount), " is your discount") 
martineau
  • 119,623
  • 25
  • 170
  • 301
310ToPoona
  • 21
  • 6

2 Answers2

1

This is the correct syntax

if points <= 50:
    points_discount = 0.00
elif points > 50 and points<= 100:
    points_discount = 0.10
elif points >100 and points <=200:
    points_discount = 0.20
SAI SANTOSH CHIRAG
  • 2,046
  • 1
  • 10
  • 26
0

Two main problems:

  1. After every if, for, while etc, you have to use colons (:) - forgotten in line 21
  2. if statements should consist of phrases which return True or False. You wanted to find out if variable is between 2 limits, you should do it like this - elif points > 50 and points <= 100: - which both of the phrases that to the left and right of and return boolean.

The whole solution without errors:

#Define variables and collect inputs
points =  int(input("How many points do you have?:  "))
years =  int(input("How many years have you been a customer?:  "))

points_discount = float()

years_discount = float()

final_discount = float()


#if statements for the points
if points <= 50:
    points_discount = 0.00
elif points > 50 and points <= 100:
    points_discount = 0.10
elif points >100 and points<=200:
    points_discount = 0.20
elif points >200 and points<=300:
    points_discount =  0.25
else:
    points_discount = 0.30

#if statement for the years as a customer
if years < 5:
    years_discount  = 0.00
else:
    years_discount = 0.05

#formula for additional discount

final_discount = points_discount + years_discount
print(str(final_discount), " is your discount")
Yossi Levi
  • 1,258
  • 1
  • 4
  • 7
  • @JohnKugelman thank you for the explanation. I see I was missing the variable of points on the right side of the if/elif statements. Another question I have is line 12, the final print statement always prints 0.00 even with ```final_discount = points_discount + years_discount``` – 310ToPoona Sep 19 '20 at 15:35
  • edited to solve your extra issue. that was because you used `==` instead of `=` for assignment. `==` is used to compare elements – Yossi Levi Sep 19 '20 at 15:40