我在一個非常基本的介紹級編程課程,我正在學習函數。我的代碼不停地將調用返回到我的程序結尾處的「main()」作爲語法錯誤。我又是超級壞在這所以不要評判我所有的錯誤main()回來作爲無效語法
def main():
speed = int(input('Enter the speed of the vehicle in mph: '))
while speed < 0:
print('Speed must be greater than zero')
speed = int(input('Enter a valid speed: '))
time = int(input('Enter the number of hours traveled: '))
while time < 0:
print('Time must be greater than zero')
time = int(input('Enter a valid time: '))
show_travel(speed,time)
def show_travel(speed,time):
print('Hours\tDistance Traveled')
print('----------------------------------------')
for time in range(1, time + 1):
distance = speed * time
print(format(time, "d"), format(distance, "20.2f")
main()
當我運行它,它與主高亮說語法錯誤
你'而速度<0:'語句縮進一個水平向右 – karthikr
看起來像縮進問題,... – alfasin
應該在哪裏的人呢? –