LearnPython - Variable Types (2/3)


#1

https://www.codecademy.com/courses/learn-python/lessons/python-syntax/exercises/booleans?action=lesson_resume

If the lesson accepts only “True” and “False” for a Boolean (“my_bool”) why does the lesson accept for an integer variable (“my_int”), a non-integer value (7.9 for example, instead of the suggested 7)?

Am I making an incorrect assumption here, or is the programming behind the lesson itself not as “tight” as it should be?

```python

Replace this line with your code.

<do not remove the three backticks above>

#2

Booleans may only be True or False… It’s like a lightswitch, on or off.

In Python, you do not specify variable types… Assigning 7.9 to my_int does not throw an error… It simply assigns a float to what you’d (the human reading the code) assume would be an integer variable. So it’s not ideal to name your variables that way if you don’t plan to type them the same way, but no errors will be thrown.

With regards to why the lesson allows it to be passed… There could be several reasons why that would happen, none of them related to how you typed your program. In this case, I would move on, and stick to the instructions.

my_int = 7
my_float = 1.23
my_bool = True

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.