+ 3
What is the problem with this code. It is not running in solo learn.
d=input() t=input() print("speed =" +str(d/t) + " km/h")
3 Answers
+ 3
Before the calculation d/t, you should convert the inputs into numbers, like in "d=int(input())" for example. The reason is that input() always returns a string of characters.
BTW I don't think it's a specific problem at Sololearn.
+ 1
@Samrocz just as Alvaro had said your variable d and t are holding a string value already its the default return type for the method "input", so its best practise for you to convert this value before using them in your code.
trying adding this after declaring d and t
print (type(d),type(t))
and you would see that at that point before your print d and t are still of type <class, String>
i am sure you are getting a TypeError and that's because you are asking the program to divide a string by a string it wont work that way so before assigning this values to d and t variables do something like this :
d=float(input())
t=float(input())
that way the values returned from "input" are first converted before been assigned to d and t this should fix the error
you should use float cause you would be dividing and you don't want to always get a whole number
i hope this helps you
0
Thanks to all