I tried putting a period after my variable name to make it a float so my result would be a float, but it gave an error. Why is this?
While it’s perfectly valid to make an integer a float by typing a period after the number, we cannot do the same to a variable, even though an integer is stored inside of it. If you try doing something like
cucumbers. it will give you an error that says invalid syntax because a period after a variable name does not do what we want in this case.
Instead, we make use of the handy, built-in
float() function! You can use it by writing any number or string between its parentheses, like so: