2017-04-22 79 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

感谢人,它只是我的第一天与蟒蛇 –