Understanding Data Types
Your supplies are stored, but not everything in the wilderness is so simple. Python has several data types, each with a purpose. In this step, you will explore the common data types: integers, floats, strings, and booleans.
Enhance your /home/labex/project/base_camp.py
script by now assigning appropriate data types to your variables. Let's specify exactly what type of values we're dealing with for clarity.
## base_camp.py
water = int(100) ## Gallons of water
food = float(50.5) ## Pounds of food, and we're carrying halves
ammunition = 40 ## Rounds of ammunition are always whole numbers
camp_name = "Fort Python" ## The name of your camp
enemy_visible = False ## There's no enemy in sight right now
Now, let the script tell us what we have by printing each variable and its type:
print('Water:', water, type(water))
print('Food:', food, type(food))
print('Ammunition:', ammunition, type(ammunition))
print('Camp Name:', camp_name, type(camp_name))
print('Is the enemy visible?', enemy_visible, type(enemy_visible))
Run your enhanced script again:
python3 /home/labex/project/base_camp.py
Check for your supplies and their types in the output. Your terminal should show:
Water: 100 <class 'int'>
Food: 50.5 <class 'float'>
Ammunition: 40 <class 'int'>
Camp Name: Fort Python <class 'str'>
Is the enemy visible? False <class 'bool'>