At this point I'm totally lost. For each task I don't understand how to even start coding, I just go to this forum to find the answer. The issue might be that I didn't fully understand what things like str, int and() float() really was and also that I have forgotten the lecture from previous task. So, should I just try to do my best and cuntinue or start from beginning again? Will I get it later?
First off, I am going to tell you something. Do not be afraid to fail, failures teach us so much it is scary. Also do not be afraid to succeed either because that can happen.
One thing you should always keep in mind is you only fail if you do not continue, success is a bunch of failures followed by success.
float() are all data types in Python. Not a hard thing to remember once you understand what they are. They are the basis of what you will work with in Python or any other programming language. You can create your own data types but right now that will be to complex.
int() data types are any whole number positive or negative,
float() data types are any number positive or negative that can also contain a decimal and any number of positions. Python does support unlimited precision floating points if you want it to. Lastly,
str() data types are any combination of characters. These can be numbers letters any symbol does not matter.
If you still need help feel free to ask.
thanks for the reply!
I will keep on coding then.
So what is the different between:
fruit = "Banana" or fruit = str(banana)?
Fruit str(banana) is attempting to convert banana to a string, but this will not work because you must tell the compiler whether banana is a list of characters or not(string). And if you do write banana as 'banana' or "banana" it would be redundant because you are converting a string to a string. EX. str("banana") #converting string to a string;
It would make more sense if you were passing in an number as an argument,
EX. str(5) would turn into the string "5", and it would no longer be a usable number.
Hope this cleared things up.
good answer by leo-crimson ,
fruit = "banana" stores banana (string) in variable fruit
now if you give print fruit -> it prints banana
however when you do fruit = str (banana) -> it doesnt know what banana is as "banana" is not defined
You are not alone, i have to go to the Q&A Forum for almost every problem and i am only 20% done with python.
float class certainly does not, as you can tell by doing:
print 1.1 + 2.2 == 3.3 # False
You can store numbers with a high precision by using a different data type but that still won't be infinitely precise.
int class scales up as far as your machine allows, perhaps that's what you're thinking of.
Floating point numbers are approximations.
True that it does not support infinite precision of floats, though float only displays an approximate to what is actually stored.
That is because of how the floats are stored in binary, it comes down to a hardware issue not a language issue, most computers only display to the 17th decimal place unless otherwise told.
What does 0.1 mean to a computer
0.1 == 0.1000000000000000055511151231257827021181583404541015625
There are several built-in modules that increase the precision of floats and you can get the exact representation in hexadecimal but even then it is still a hard ware issue.
If you would like to see the exact numerical representation of a number do the following,
from decimal import Decimal print(Decimal.from_float(0.1)) # OUTPUT: Decimal('0.1000000000000000055511151231257827021181583404541015625')
You have to adjust for the simple fact that
0.1 in computer does not
Want to see what is really going on in your
1.1 + 2.2 == 3.3 let's show ya.
from decimal import Decimal Decimal.from_float(1.1) # Decimal('1.100000000000000088817841970012523233890533447265625') Decimal.from_float(2.2) # Decimal('2.20000000000000017763568394002504646778106689453125') Decimal.from_float(1.1) + Decimal.from_float(2.2) # Decimal('3.300000000000000266453525910') Decimal.from_float(1.1) + Decimal.from_float(2.2) == 3.3 # False Decimal.from_float(1.1) + Decimal.from_float(2.2) == Decimal.from_float(3.3) # False Decimal.from_float(3.3) # Decimal('3.29999999999999982236431605997495353221893310546875')
One must love floating point division when it comes to computers.
0.1 is equal to 0.1 anywhere. Floats can't represent this value, so a value that can be represented by floats is used instead.
The term "infinite precision" shouldn't be used in proximity of "floating point numbers" lest it confuse somebody.
yea I'm kinda the same I write the code lets say 80% right, but because the language barrier I find myself wondering what does it exactly wants me to do
Okey. This helps alot, but I still dont understand other many thing, such as, what is len()?
Thanks for the relply