- MEMORIES
- 3.1 Variables and Assignments
- 3.2 Data Abstraction
- 3.3 Mathematical Expressions
- 3.4 Strings
- 3.5 Booleans
- 3.6 Conditionals
- 3.7 Nested Conditionals
- 3.8 While Loops
- 3.10 Lists
MEMORIES
Something that will help teachers or peers recall my presentation was practicing our presentation together during office hours. It was a unique experience for us all collaborating on a shared repository because we did encounter a lot of merge errors at the beginning, but we were able to push through and figure out the issues we had together.
3.1 Variables and Assignments
- Definition: Variables store values that can be used and modified throughout your program.
Example:x = 10
assigns the value10
to variablex
. - Reassigning Variables: You can change the value of a variable at any time.
Example:x = 20
changesx
to20
. - Interactive Challenge:
Task: Create a variableage
and assign it your current age. Now, reassign it with what your age will be in 10 years.
3.2 Data Abstraction
- Definition: Data abstraction hides complexity by allowing you to work with data without knowing the details.
Example: Arrays or lists abstract away how the data is stored in memory. - Purpose: It simplifies the way you handle complex data, like files or databases.
- Interactive Challenge:
Task: Think of a complex concept (like a playlist of songs). Now abstract it into a simple list.
Example:playlist = ["Song1", "Song2", "Song3"]
3.3 Mathematical Expressions
- Basic Operations: Computers use operators like
+
,-
,*
, and/
for calculations.
Example:y = (5 + 3) * 2
- Order of Operations: Use parentheses to control operation order.
Example:result = (2 + 3) * 4
gives20
. - Interactive Challenge:
Task: Solve the expression((8 - 3) * 2) / 5
. What is the result?
3.4 Strings
- Definition: Strings are sequences of characters enclosed in quotes.
Example:greeting = "Hello, world!"
- String Concatenation: Combine strings using
+
.
Example:full_name = first_name + " " + last_name
- Interactive Challenge:
Task: Create a variable calledfavorite_food
and assign it your favorite food. Then, print: “I lovefavorite_food
!”
3.5 Booleans
- Definition: Booleans represent
True
orFalse
values.
Example:is_sunny = True
- Logical Operators: Use
and
,or
,not
to combine conditions.
Example:is_warm = is_sunny and temperature > 70
- Interactive Challenge:
Task: Setis_tired
toTrue
orFalse
depending on how you feel. Then, print: “I am tired:is_tired
.”
3.6 Conditionals
- Definition: Conditionals allow your program to make decisions using
if
,else
, andelif
.
Example:if x > 10: print("x is large")
- Comparison Operators: Use
==
,!=
,>
,<
for comparisons.
Example:if age == 18: print("You're an adult!")
- Interactive Challenge:
Task: Create a conditional that checks if your favorite number is greater than 10. Print an appropriate message.
3.7 Nested Conditionals
- Definition: Nested conditionals are
if
statements inside otherif
statements.
Example:
```python if age > 18: if has_id: print(“You can enter”)
3.8 While Loops
- Definition: A
while
loop continues to run as long as its condition isTrue
.
Example:
```python count = 0 while count < 5: print(count) count += 1
3.10 Lists
- Definition: A list is an ordered collection of items, which can be of any data type (numbers, strings, etc.).
Example:fruits = ["apple", "banana", "cherry"]
- Accessing List Elements: You can access items in a list using their index, starting from
0
.
Example:print(fruits[0]) # Outputs: "apple"
- Interactive Challenge:
Task: Create a list of your top three favorite hobbies and print each one in a new sentence.