JUNIOR

ACADEMY

10/21/2016

sublist indexing

  • Lists can hold any form of data in each index, including other lists!
    • listA = ['john', 'irene', ['brooks', 'tristan'], 'yukio']
    • listB = [1, 2, [3, 4], 5, [6]]
  • You access the elements in the sublists by using another set of brackets with its index
    • tristan == listA[2][1]
    • 6 == listB[?][?]

Suzuki is a monk who climbs a large staircase to the monastery everyday as part of a ritual. Some days of the week he climbs more stairs than others depending on the number of students he must train during that day of the week. He is curious how many stairs he climbs over the course of a year and has gathered sample data points for each of the seven days of the week.

You must write a function called SuzukiStairs that receives a list containing data collected by Suzuki. The list consists of 7 sublists, one for each day of the week. The sublists will have different numbers of data points because Suzuki sometimes forgot to record data for a given day. For example:

[[23, 25, 32], [4, 2], [1, 1, 1, 3], [15, 18, 19], [2], [31], [11, 13, 9]]
To get the best estimate, first determine the average number of stairs for each day of the week from the sample data set. Next, add those averages together to the best estimate of the average stairs in a week. Finally, multiply the results by 52 to get the estimate for the number of stairs Suzuki will climb in an entire year.

dictionaries

  • Dictionaries are collections of key-value pairs
  • Store information about anything
    • dog = {"color": "brown", "age": 6}
    • print(dog["color"])
    • print(dog["age"])
  • Define dictionaries in curly braces {}, with the key in quotes, and its value after a colon
    • The value can be any data type
  • Access dictionary values by calling the key in brackets []

dictionaries

  • Modify values in a dictionary by giving the name of the key in brackets and then the new value
    • dog['color'] = 'black'
  • Add keys the same way, except with a new key name
    • dog['size'] = 'medium'
  • Remove key-value pairs with the del statement
    • del dog['color']

dictionaries

  • The previous examples involved storing different kinds of information about one object (a dog)
  • You can use a dictionary to store one kind of information about many objects
  • (You can also format dictionaries like this:)
favorite_languages = {
    'john': 'C',
    'irene': 'Python',
    'yukio': 'Python',
    'charles': 'JS',
    }

dictionary exercise

Use a dictionary to store information about a person you know. Store their first name, last name, age, and the city in which they live. You should have keys such as first_name, last_name, age, and city. Print each piece of information stored in your dictionary

group project

  • You will be working in a group to complete a new, mini-project
    • Using Git for programming collaboration
  • This small project may be expanded on later to make a full-blown CLI RPG!
    • Completely optional if you want more practice before Pygame

group project

  • Make a simple turn based RPG with combat
  • The code should contain:
    1. A menu where you can select four attacks that do different amounts of damage or have different effects
      • Use randint
    2. Enemies that fight back
    3. A user action or an enemy action will count as a turn
    4. The game ends when someone reaches zero health
    5. (Optional) A random encounter generator
      • There are multiple enemies you can fight

survey!

https://www.surveymonkey.com/r/C8Y8TYT

Jr. DevLeague Academy PM 10/21/16

By jtheadland

Jr. DevLeague Academy PM 10/21/16

  • 657