The Noobs of Python: Ep.1.0 - The Introduction

Okay, as mentioned here SublimeText does not support the feature, but there are workarounds. It blows my mind why this is not a standard feature, but anyway. Your suggestion works and I thank you, sir :)

I will check the videos to make sure I didnt miss anything.

BTW, If anyone is searching for a IDE to use, here is a nice comparison:

1 Like

Just get SublimeREPL from the sublime package manager. Just like you did with the linter.

Its time to get to some Code my fellow Code_Warrior !!

bim = float(weight1) / float(height1) **2

You don't need to cast these to floats. It'll be done automatically for you.

It's worth mention that you need to be careful with floats, btw. You can end up with some tiny inaccuracies.

e.g.

>>> 0.3 + 0.03
0.32999999999999996
2 Likes

@_Cat Thanks a lot for the tip. However in that example weight and height are strings assigned by input function

>>> var1 = input()
2
>>> var2 = input()
3.68
>>> print(var1 + var2)
23.68
>>>

I know now that i could have cast the class on the very begging like this:

>>> var1 = int(input())
2
>>> var2 = int(input())
4.89
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '4.89'
>>>

But i specify that to be integer its gives me error when you put in a fraction. Also i know there must be a way for python to recognize the input and assign appropriate type to variable but since I'm still on the begining of my python journey that's all i could come up with at the time.
Also i noticed when i tested the code initial in the python shell it did what you just described with weird fractions. However when it was saved to a file and ran it worked fine. Perhaps you could explain why that is?

I'd cast them to floats upon input instead. The errors you're given when a user inputs a value that can't be converted to a float/int make more sense then - it points to the line on which they're inputted.

Also, it saves you from having to cast it to the desired type on every instance of you using that value later on.

>>> var2 = float(input())
4.89
>>>

would be fine.

1 Like

Yes, I understood that bit. I only did the int() in the previous example to show that i have to use float since people will put in fractions. i'll try to cast int/floats on input next time.
But when i asked for the explanation i was more referring to the weird fractions/output you were getting when working on floats in the python shell??

>>> a = 0.3
>>> b = 0.04
>>> a + b
0.33999999999999997
>>>

But when i saved this as a python script and ran the output was 0.34 as it should

When I do the same I still get the inaccuracies. No clue.

1 Like