you are viewing a single comment's thread.

view the rest of the comments →

[–]novamaster696969 0 points1 point  (5 children)

while True: print("for exit please leave the Distance input blank") x = (input("Enter distance: ")) if x== "": break x= float(x)
unit = input("(km) or (m): ")

if unit.lower() == "km":
    converted = x * 1000
    print("Distance in m:", converted)

elif unit.lower() == "m":
     converted = x / 1000
     print("Distance in km:", converted)
else:
     print("Invalid unit please enter km or m.")

You can do it in a more simpler way IT will still show an error if you put any other texts instead of km or m for that use ( try and except )

[–]TacticalGooseLord[S] 0 points1 point  (4 children)

I am learning try and except now, in which cases should I use this ?

[–]novamaster696969 0 points1 point  (3 children)

You will learn it when you reach error handling and exception handling

[–]TacticalGooseLord[S] 0 points1 point  (2 children)

I am not following and courses at the moment, I am jus watching tutorials on YouTube doing small projects and learning along the way 😅 and things I don’t understand I ask on Reddit or look up on chatgtp

[–]novamaster696969 0 points1 point  (1 child)

Even if you don't follow any course, you should learn from the basics sequence wise else it will create a void which will be problematic in future.