Ask coding questions

← Back to all posts
Speed, Distance, Time
OldWizard209 (1537)

Hi, I ma a beginner and I was making this program which was going to give you the speed if you enter the distance and time and it was going to give you the time if you entered the distance speed. I am a beginner in Python. I have posted the code. Please check it and see the error and tell me how to fix it. This is the code https://repl.it/@abdullahrajput9/SpeedTime#main.py and this is the error:

And BTW I have just made the Speed finding code. Soo, when the program runs you have to enter the number 1 and then you can proceed. Thanks for helping :)

Answered by SUHASTADIPARTH1 (190) [earned 5 cycles]
View Answer
Comments
hotnewtop
SUHASTADIPARTH1 (190)

This is how you do the speed formula in python:

d = input("Distance? ")
t = input("Time? ")

d = int(d)
t = int(t)

speed = d / t
print(speed)
OldWizard209 (1537)

Thanks @SUHASTADIPARTH1 It fixed my code Thanks A LOT MAN

RYANTADIPARTHI (6018)

use int in your code

distance = int(your input)
speed = int(your input)

so they need to be ints

RYANTADIPARTHI (6018)

@abdullahrajput9 np, can you please mark my answer? Thanks!

OldWizard209 (1537)

UMM Actually someone answered first and I marked him, I don't
think I can mark again. I tried but it didn't work. Really Sorry @RYANTADIPARTHI

OldWizard209 (1537)

But you can always have an upvote @RYANTADIPARTHI

RYANTADIPARTHI (6018)

@abdullahrajput9 it's np, at least i got an upvote right? :)

OldWizard209 (1537)

More than 1 upvote LOL (Not taking credit BTW) @RYANTADIPARTHI

RYANTADIPARTHI (6018)

@abdullahrajput9 could you explain the last part a bit better? thx

zplusfour (901)

@RYANTADIPARTHI cycle farming, replit cycles aren't youtube likes

OldWizard209 (1537)

Umm NVM @RYANTADIPARTHI Just thanks for the help :)

OldWizard209 (1537)

Not advertising guys but this is the final version of what I was planning to make https://repl.it/talk/share/Speed-Distance-Time-Finder/60420 ((Thanks to you all)) Not looking for upvotes either :)

Muffinlavania (1526)

The error says
unsupported operator type(s) for / : str and str
This is saying that the two 'numbers' are actually phrases! (Example: It is '2' instead of 2) So to convert them you have to use int(), like this

distance=int(input("Enter your distance")) #The int makes it an interger, but if you enter anything but a number it will error
speed=int(input("Speed now pls")) #Again

And then the formula should work?

OldWizard209 (1537)

Thank you SOOOOOOOOO MUCH @Muffinlavania It fixed my code. Thanks a lot

OldWizard209 (1537)

Not advertising guys but this is the final version of what I was planning to make https://repl.it/talk/share/Speed-Distance-Time-Finder/60420 ((Thanks to you all)) Not looking for upvotes either :)

SUHASTADIPARTH1 (190)

You have that error, you have to convert those numbers (which are strings by default) to integers by doing int() and the number or variable inside those brackets.

OldWizard209 (1537)

Not advertising guys but this is the final version of what I was planning to make https://repl.it/talk/share/Speed-Distance-Time-Finder/60420 ((Thanks to you all)) Not looking for upvotes either :)