0

Hey guys,

I want to make a simple program which calculates speed, distance and time.

This is the code I used:

```
a=input("1)Find speed\n2)Find distance\n3)Find time\n4)Quit\n")
while a!=4:
if a==1:
d=input("\nEnter distance: ")
t=input("Enter time: ")
print ("Speed: "+str(d/t)+"\n")
elif a==2:
s=input("\nEnter speed: ")
t=input("Enter time: ")
print ("Distance :"+str(s*t)+"\n")
elif a==3:
s=input("\nEnter Speed: ")
d=input("Enter distance: ")
print ("Time :"+str(d/s)+"\n")
a=input("1)Find speed\n2)Find distance\n3)Find time\n4)Quit\n")
```

But, my question is, can't it be done like this:

```
s=input("Speed: ")
d=input("Distance: ")
t=input("Time: ")
#Considering 1- is the symbol for 'find'
s=d/t
if(s==1-):
print (s)
elif(d==1-):
print (d)
elif(t==1-):
print (t)
```

Won't Python itself decide that in if else case 2, since speed and time are provided, it has to calculate time using formula 's=d/t'?

Thanks