231k views
3 votes
Write multiple if statements. If car_year is 1969 or earlier, print "Few safety features." If 1970 or later, print "Probably has seat belts." If 1990 or later, print "Probably has antilock brakes." If 2000 or later, print "Probably has airbags." End each phrase with a period and a newline.

Sample output for input: 1995
Probably has seat belts.
Probably has antilock brakes.

My code:

car_year = int(input())

if car_year <= 1969:
print('Few safety features.')
elif car_year ==1970:
print('Probably has seat belts.')
elif car_year >= 1990:
print('Probably has seat belts.\\Probably has antilock brakes.')
else:
car_year >= 2000
print('Probably has airbags.')

My output that keeps failing:
Testing with input: 2001
Output differs. See highlights below.
Special character legend
Your output
Probably has seat belts.
Probably has antilock brakes.
Expected output
Probably has seat belts.
Probably has antilock brakes.
Probably has airbags.

User Tran Quan
by
4.7k points

2 Answers

4 votes

Your problem is that you're using elif and if statements. As soon as one of your statements is true, the other ones don't run. You need to use multiple if statements instead of the elif and else statements. For instance:

car_year = int(input())

if car_year <= 1969:

print('Few Safety features.')

if car_year >=1970:

print('Probably has seat belts.')

if car_year >= 1990:

print('Probably has antilock brakes.')

if car_year >= 2000:

print('Probably has airbags.')

I wrote my code in python 3.8. I hope this helps.

User Newmangt
by
3.9k points
5 votes

Answer:

car_year = int(input())

if car_year <= 1969:

print('Few safety features.')

if car_year >=1970:

print('Probably has seat belts.')

if car_year >= 1990:

print('Probably has antilock brakes.')

if car_year >= 2000:

print('Probably has airbags.')

Step-by-step explanation:

Just needed to change the capitol S on the previous code to a small s. Works just fine. in Python.

User Roy Holzem
by
4.3k points