0

Conversion resulting in 0?

Here's the relevant parts of my script : Inch = 1 Ft = inch/12 #Ft = inch*0.083 print "" I am 5.9 therefore I am %d"" % (5.9*ft) Keeps giving 0" tried changing from "ft = inch*0.083" thinking it was because that was a zero but obviously that wasn't the problem. Sorry, I know this is a daft question but I'm not sure what I'd even search for to find the answer.

26th Jun 2017, 9:09 PM
Piperman
10 Respostas
+ 8
Aha, now I get it. The division goes alright. You just format the string output incorrectly. %d means to format the number as integer. Try using %f for this particular case.
26th Jun 2017, 10:00 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
Glad that helped 🤓👍
26th Jun 2017, 10:15 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
I am assuming you are using Python 2.7. Try with Inch = 1.0 (explicitly write the floating point value). Python should then start treating it as a float.
26th Jun 2017, 9:14 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
Yes, you can open www.sololearn.com and copy the code to the Code Playground. Then you can save it as the python code and even run it here.
26th Jun 2017, 9:40 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 3
Wait... could you please upload the code or at least write the whole arithmetic operation?
26th Jun 2017, 9:23 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
Thanks kuba but it didn't work. I thought it was due to the original variable being an integer but I figured it wasn't as I've got a similar bit if code for weight which is working. Only difference is that the weight one results in positive numbers : Lbs=1 Kg=lbs/2.2 ... % ((74*lbs)*kg) Results in 33 Is it because lbs/12 results in a negative number? I wouldn't have thought so but it's the only difference I can see.
26th Jun 2017, 9:21 PM
Piperman
0
Codes on my laptop, is it possible to upload it onto here somehow? I can't see a way without redoing the whole thing but I could though if necessary.
26th Jun 2017, 9:28 PM
Piperman
0
Haha, thanks. I started rewriting anyway just in case I spotted anything. Just the relevant bits, I'll go add the actual script now as well. This isn't working in the playground, I'm using python 2 on my laptop, is it python 3 in the playground? The syntax error doesn't happen on the laptop anyway. But maybe you can see something I don't. Edit Yeah, just saw on the site that it's python 3. If you know python 2 I'm guessing that shouldn't be an issue tho... I hope ha
26th Jun 2017, 9:44 PM
Piperman
0
Awesome, that worked. Thanks a bunch! I wasn't sure about the format characters as the tut I'm following just introduced them, %d and %s, with no explanation as of yet. It did say to search for more but I left out 'strings' in my search and the results weren't relevant, enough for me to understand yet. Got it now though, thanks.
26th Jun 2017, 10:13 PM
Piperman