1. Hello World

  • Feel free to use your laptop

  • You are strongly encourage to work with others

    • When you get stuck, ask those sitting around you for help

    • Get used to working together in the labs

    • Peer teaching and peer learning has been empirically shown to be very effective

1.1. Pre Lab Exercises

  1. Chapter 1 exercise(s)

    • Although the exercises mention “the interpreter”, you are to use Google Colab

    • 2

    • 4

  2. Chapter 2 exercise(s)

    • 1

    • 5

1.2. Hello World

  1. Log onto your computer

  2. Log into Colab

    • If you do not have a Google account, you can make one for the purpose of this course

  3. Get Hello World working on Colab

    • If you are unsure of what this is, review Topic 1

1.3. Refreshing What We Learned

  1. Enter and run the following code

    1a = 5
    2a = a * 2
    
    • Have Python print out the type of a

  2. Enter and run the following code

    1a = 5
    2a = a * 2.5
    
    • Have Python print out the type of a

    • Is this what you expected?

  3. Complete the following

    • Make two variables and assign arbitrary numerical values to them

    • Add the variables together and assign the resulting value to a new, third variable

    • Print out the value of the third variable

1.4. Kattis

Note

You are not expected to complete all the Kattis problems. Just work on them until the time runs out. If you need help, ask those around you for help. If you’re still stuck, ask us for help.

Note

It will be a lot easier to build your solutions on Colab and then copy/paste them into Kattis.

  1. Kattis sign up (be sure to set affiliation)

    • Go to settings to do this

    • Also, I highly recommend setting your default language to Python 3

  2. https://open.kattis.com/problems/hello

  3. https://open.kattis.com/problems/carrots

    • Although I provide a working solution below, the actual task I want you to do is to look at the code, read the comments, and try to figure out what is going on

    • Talk to each other

    • Make sure it makes sense

    • Take your time

    • Ask questions

    • That’s what this is all about.

     1# This loads in the first line (it's of type STRING!)
     2# For example, if we take the first sample input of --- 2 1
     3# Then the contents of data after this line is complete is '2 1'
     4data = input()
     5
     6# This is going to sadly be *magic* code at this stage.
     7# This line *splits* the string ('2 1' in this case)
     8# into separate smaller strings. The split happens on space characters
     9# The result is a *list* of the split string (['2', '1'] in our example)
    10# We then overwrite the contents of data with this result (['2', '1'])
    11data = data.split()
    12
    13# Now data is a *list*. To access data from the list at a specific location
    14# We just *index* the list at the desired location: data[location]
    15# HOWEVER, computer scientists are weird and like to start counting at 0
    16# So, when we say data[1], we are actually getting the string '1' from data
    17# data[0] would give us '2' in this case (weird, I know, but deal with it)
    18carrots = data[1]
    19
    20# Now we just print out what we stored in carrots
    21print(carrots)
    
  4. https://open.kattis.com/problems/r2

  5. https://open.kattis.com/problems/faktor

  6. https://open.kattis.com/problems/ladder

  7. https://open.kattis.com/problems/planina