3.1.1

Blog:

Strings is a series of characters (numbers, letters, etc), one example of a string is your name or your id because strings can contain both numbers and letters.

Lists are sequences of elements with each element being a variable. An example of a list can be the names of the students in this classroom. 

Assign variable that coorelates to the function so less errors are made

3 different data types that support different data

    * integer (numbers)
    * string (or text/letters)
    * Boolean (True/False statements)

  • Questions:

    1. What exactly IS a variable?

      A variable is an abstraction inside a program that holds a value, where each variable has associated data storage that represents a single value at a time

    2. What is the best data type to represent someone's dog's name?

      String

    3. Why is it important to give variables specific names before containing values?

      So you don't get them mixed up

    4. What is the best way to represent someone's phone number?

      String

      Bonus (Not required but important to know):

    5. How can we update a variable's value

      (blank) = updated version

    6. What function is used to recieve a user's input?

      Input

Hacks: Assignment Operater: The operator used to assign a new value to a variable, property, event or indexer element. Example: X = 5 Collegeboard uses arrow symbols to assign a value to a variable. A variable, x, is initially given a value of 15. Later on, the value for x is changed to 22. If you print x, would the command display 15 or 22? The variable would display 22.

x = 22
x = 15
display(x)
15

3.1.2

Questions:

  • What is a list?

    Lists are sequences of elements with each element being a variable. An example of a list can be the names of the students in this classroom.

  • What is an element

    A fragment of computer code (can be any piece of computer readable text)

  • What is an easy way to reference the elements in a list or string?

WorldCup = ["argentina", "portugal", "france", "spain"]
print(WorldCup)
['argentina', 'portugal', 'france', 'spain']
  • What is an example of a string?
print("Hello Universe")
Hello Universe

Hacks

  • Create a list with indices
  • Index a part of the list that you created.
  • Try to index from the end

3.2.1

Hacks

  • The following code is incomplete. Its intended purpose is to increase three numbers, all of which ask for user input, by an amount specified the user. The input code is abstracted, but the actual logic isn't connected to the abstraction.
num1=input("Input a number. ")
num2=input("Input a number. ")
num3=input("Input a number. ")
add=input("How much would you like to add? ")

# Add code in the space below

numlist = [int(num1), int(num2), int(num3)]

# The following is the code that adds the inputted addend to the other numbers. It is hidden from the user.

for i in range(len(numlist)):
    numlist[i -1] += int(add)

print(numlist)
[30, 32, 34]

3.2.2

Hacks

  • On a single markdown file:

    • Insert a screenshot of your score on the python quiz

    • Insert a screenshot of your simplifying of the food list

Food = ["pizza", "hot dog", "sushi", "strawberry", "sandwich"]

display(Food)
['pizza', 'hot dog', 'sushi', 'strawberry', 'sandwich']
  • Why are using lists better for a program, rather than writing out each line of code?

    It's more efficent because rather than imputing data one by one you can do it way faster using lists.

  • Make your own list the "long and slow way" then manage the complexity of the list

country1 = "Iran"
country2 = "Switzerland"
country3 = "Japan"
country4 = "Ghana"

# Inputing values one by one

print(country1, country2, country3, country4)
Iran Switzerland Japan Ghana
countries = ["Iran", "Switzerland", "Japan", "Ghana", ]
# Using a list to put values into the countries variable.
display(countries)
['Iran', 'Switzerland', 'Japan', 'Ghana']