Lesson 2 Flashcards
Data Types and variables
1
Q
Different data types
A
String - str()
Integer - int()
Boolean True/False - bool()
Float Numbers with decimel - Float()
2
Q
Instructions for [B/I/A] Exercise 2.1: Using String and Integer Data Types
- Step 1 for Line 1 of Code: Define name as a string variable & call it Darth Vader
- Step 2 for Line 2 of Code: Print the name Darth Vader
- Step 3 for Line 3 of Code: Define age as an integer variable and make it 19
- Step 4 for Line 4 of Code: Print the age
A
name=str(“Darth Vader”)
print(name)
age=int(19)
print(age)b
3
Q
Instructions for [B/I/A] Exercise 2.2:
Using Floating and Boolean Data Types
- Step 1 for Line 1 of Code: Define a Boolean variable called i cannot do it as false
- Step 2 for Line 2 of Code: Print the variable
- Step 3 for Line 3 of Code: Define a floating variable called the answer as 42.01
- Step 4 for Line 4 of Code: Print the variable
A
i_cannot_do_it = Bool(false)
print( i_cannot_do_it)
answer = float(42.01)
print(answer)
4
Q
Instructions for [B/I/A] Exercise 2.3:
How to Change the Content or Type of a Variable
C3P0 is 1.75 meters tall & R2D2 is 1.09 meters tall.
- Step 1: Create a variable called height as a string type
- Step 2: Assign the height a value of 1.09
- Step 3: Print the height of R2D2
- Step 4: Change the height data type from string to floating
- Step 5: Add 0.66 to 1.09
- Step 6: Print the new height
A
height = 1.09
print(height)
height = float(1.09)
new_height = 0.66 + height
print(new_height)