2017-04-22 80 views
-5
# Kinematics clculator 

print('Kinematics Calculator') 

print('If either one of the three values(s,v,t) is not given then put its value = 1') 


s = float(input('Enter your distance = ')) 
print(s) 


t = float(input('Enter your time = ')) 
print(t) 


v = float(input('Enter your velocity = ')) 
print(v) 


if 'v == 1' : 
    print('velocity = '+ str(s/t)) 

elif 't == 1' : 
    print('time = '+ str(s/v)) 

else : 
    's == 1' 
print('distance = '+ str(v*t)) 

幫我改正這段代碼。每當我嘗試計算什麼比別的「速度」它總是使用第一個打印命令即如何在Python中調試我的if和elif語句?

print('velocity = '+ str(s/t)) 
+0

你應該縮進它'打印('速度= '+ STR(S/T))'' –

+3

' V == 1''和兄弟姐妹_strings_。 – ForceBru

+0

你是什麼意思? –

回答

4

'v == 1'結果始終爲true,因爲它是一個非空字符串。你應該使用

if v == 1: 
    print('velocity = '+ str(s/t)) 

elif t == 1: 
    print('time = '+ str(s/v)) 

else: 
    print('distance = '+ str(v*t)) 
+0

感謝人,它只是我的第一天與蟒蛇 –