MYTUTOR SUBJECT ANSWERS

227 views

How could I write a program to convert Km/h to m/s in python

First we need to know that the conversion factor for km/h to m/s is 3.6km/h=1m/s

Next we need to read in a value from the user. This can be done with 'input' function as follows:

KMHvalue= input("Enter a value in km/h: ")

we will then need to use our conversion to convert the value into m/s

MSvalue=KHMvalue/3.6

Then we can output the answer using the 'print' function:

print("your value in m/s is: "+MSvalue)

hence the whole program is:

KMHvalue= input("Enter a value in km/h: ")
MSvalue=KHMvalue/3.6
print("your value in m/s is: "+MSvalue)

We could make this program more sophisticated by allowing the user to select if they want to convert from km/h to m/s or the other way around. A sample script to do this would be:

choice=input("Please enter 1 to convert km/h to m/s or 2 to convert m/s to km/h")
​if choice==1
    KMHvalue= input("Enter a value in km/h: ")
    MSvalue=KHMvalue/3.6
    print("your value in m/s is: "+MSvalue)

else if choice==2
    MSvalue= input("Enter a value in m/s: ")
    KMHvalue=MSvalue*3.6
    print("your value in km/h is: "+KMHvalue)

else
​    print("Invalid Choice")

Sarah W. A Level Maths tutor, GCSE Maths tutor, A Level Chemistry tut...

5 months ago

Answered by Sarah, a Mentoring Python tutor with MyTutor


Still stuck? Get one-to-one help from a personally interviewed subject specialist

0 SUBJECT SPECIALISTS

About the author

PremiumSarah W. A Level Maths tutor, GCSE Maths tutor, A Level Chemistry tut...

Sarah W.

Currently unavailable: for new students

Degree: Robotics (Masters) - Bristol University

Subjects offered:Python, Physics+ 3 more

Python
Physics
Maths
Electronics
Chemistry
Biology

“About Me: I am currently a Masters student in Robotics at the University of Bristol. My choice of degree was based on my love for hands on science. I will try to pass on this love to you during my tutorials! I have alot of experience...”

You may also like...

Posts by Sarah

How could I write a program to convert Km/h to m/s in python

How do you solve 3sin2AtanA=2 for 0<A<180?

In the presence of ultraviolet light, ethane and chlorine react to give a mixture of products. What are the products of this reaction?

Two railway trucks of masses m and 3m move towards each other in opposite directions with speeds 2v and v respectively. These trucks collide and stick together. What is the speed of the trucks after the collision?

Other Mentoring Python questions

How could I write a program to convert Km/h to m/s in python

Creating string from multiple strings(or characters)

Write a program that can convert between celcius and farenheit temperature scales

View Mentoring Python tutors

We use cookies to improve your site experience. By continuing to use this website, we'll assume that you're OK with this. Dismiss

mtw:mercury1:status:ok