編碼:
class Car:
y = 0
x = 0
x_miles = y / 5280
y_miles = x / 5280
direction = 0
speed = 100
fps = speed * 1.467
Cords = {x}, {y}
Cords_miles = x_miles, y_miles
def driving(self):
drv = 'start'
while drv != 'stop':
if Car.direction == -270:
Car.direction = 90
elif Car.direction == 270:
Car.direction = -90
elif Car.direction == -180:
Car.direction = 180
drv = input('Say W(Forward), S(Stop), A(TurnLeft), D(TurnRight), C(GetCords): ').lower
if drv == 's':
print('this never gets executed, as well as the elifs statements after')
else:
print('this always gets executed')
問題是當我呼叫該函式然后輸入一個輸入時,例如,如果我給它一個字母 s,它會立即跳到 else 陳述句。如果我輸入 s,這是輸出:
Say W(Forward), S(Stop), A(TurnLeft), D(TurnRight), C(GetCords): s
this always gets executed
我似乎無法修復它,所以如果有人可以提供幫助,那就太好了!
uj5u.com熱心網友回復:
你在你之后缺少括號.lower。正如您可以在此處閱讀的那樣,如果沒有括號,您只是設定了對 lower 方法的參考,但實際上并沒有呼叫它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/478254.html
