我正在编写一个包含速度限制和while和if语句的程序。我尝试使用它,以便在输出结果后询问是否要使用while循环重做该程序。
听说如果我有一个太多的括号或一个开放的括号,就会发生这种情况。我所有的括号都没问题。
ques1 = int(input('What speed is the car travelling? '))
check = ques1
running = True
while running == True:
if 0 <= check <= 50:
print('You are clear.')
if 51 <= check <= 60:
print('10 demerit points')
if 61 <= check <= 70:
print('20 demerit points')
if 71 <= check <= 80:
print('30 demerit points')
if 81 <= check <= 90:
print('50 demerit points')
if 91 <= check <= 1000:
print("100 demerit points")
dasques = input('Do you want to try again? y/n '):
if dasques == ('n'):
running = False
预期输出:
Hoping to get :
50 demerit points
Do you want to try again? y/n
但是我得到
“无效语法”,后跟冒号: [dasques = input('您要重试吗?是/否'):]
以红色突出显示。
答案 0 :(得分:1)
尝试一下
dasques = input('Do you want to try again? : y/n ') # you can keep ':' inside the string
if dasques == ('n'):
running = False
答案 1 :(得分:0)
请在下面的代码行中更改
<div class="links"><a> <img src="mustang.jpg" width="200" height="150"white-space= "nowrap"><span> Ford Mustang MSRP: From $26,395
Horsepower: 310 to 480 hp
MPG: Up to 21 city / 32 highway
Curb weight: 3,532 to 3,825 lbs
Engine: 2.3 L 4-cylinder, 5.0 L V8
For the convisrtable version the price starts at $31000</span></a>
</div>
<div class="links"> <a> <img src="challenger.jpg" width="200" height="150"white-space= "nowrap"><span>Dodge Challenger MSRP: From $27,845
Horsepower: 305 to 797 hp
MPG: Up to 19 city / 30 highway
Curb weight: 3,894 to 4,448 lbs
Engine: 3.6 L V6, 5.7 L V8, 6.2 L V8, 6.4 L V8
There are other models of this specific car, and the price can go as high as $37000</span></a>
</div>