+ 3
What am I doing wrong here?
Obviously a syntax issue, I tried with and without parentheses, tinkered around with it, but the last thing I want to do is paste it into AutoGPT and have her fix it and make me pancakes while changing my brakes on the car and curing Cancer while massaging my feet 😆 --------------- #sets the value of age age = int(input()) if age (>= 18) and (<= 74): # executed only if customer is over-age print("Regular price") elif (age >= 75) and (<= 99): #executed only if age is less than 18 print("Discount Price, You Old Croaker") elif age >= 100: print("Are you gonna die? Take this at no charge!") else age < 18: print("No charge")
5 ответов
+ 5
try this code:
the syntax in the if statments was incorrect, and else statments cannot have a condition 😄
#sets the value of age
age = int(input())
if age >= 18 and age <= 74:
# executed only if customer is over-age
print("Regular price")
elif age >= 75 and age <= 99:
#executed only if age is less than 18
print("Discount Price, You Old Croaker")
elif age >= 100:
print("Are you gonna die? Take this at no charge!")
elif age < 18:
print("No charge")
else:
print("No charge")
+ 3
age = int(input())
if 18 <= age <= 74:
print("Regular price")
elif 75 <= age <= 99:
print("Discount Price, You 0ld Croaker")
elif age >= 100:
print("Are you gonna die? Take this at no charge!")
else:
print("No charge")
You had 2 errors
1. You weren't assigning your variable to your AND condition
2. You assigned a condition to your ELSE, which is designed to return a statement when no other conditions are met
+ 1
#sets the value of age
age = int(input())
if age (>= 18) and (<= 74):
# executed only if customer is over-age
print("Regular price")
elif (age >= 75) and (<= 99):
#executed only if age is less than 18
print("Discount Price, You Old Croaker")
elif age >= 100:
print("Are you gonna die? Take this at no charge!")
else:
print("No charge")
+ 1
Thank you both. The first reply worked. The second and third solution pulled an error due to the parentheses around the greater than and equal to logic condition Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
start(fakepyfile,mainpyfile)
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), __main__.__dict__)
File "<string>", line 3
if age (>= 18) and (<= 74):
^
SyntaxError: invalid syntax
[Program finished]
0
you wrote syntax wrong, after else you gave it condition age <18❌
change it to elif✅