General Notes


Submit the following programs via Gradescope:


    Programming Exercises


  1. Due Date: September 10 Reading: Lab 1

    Write a program that prints "Hello, World!" to the screen.

  2. Due Date: September 11 Reading: Lab 1

    Write a program that draws an Octagon using the turtle library.
    program 2

    Note: Whenever submitting a turtle program, choose a name for your file that is not turtle.py. When executing the "import turtle" statement, the computer first looks in the folder where the file is saved for the turtle module and then in the libraries (and other places on the path). So, it thinks the module is itself, causing all kinds of errors. To avoid this, name your program something like "myTurtle.py" or "program2.py".

  3. Due Date: September 12 Reading: Lab 1

    Write a program that implements the pseudocode ("informal high-level description of the operating principle of a computer program or other algorithm") below:

            
              Repeat 36 times: 
                Walk forward 100 steps
                Turn left 145 degrees 
                Walk forward 10 steps 
                Turn right 90 degrees 
                Walk forward 10 steps 
                Turn left 135 degrees 
        	    Walk forward 100 steps 
             
          
    The result should look as follows:

  4. Due Date: September 13 Reading: Lab 1

    Write a program that will print "I love Python!" 25 times.

    The output of your program should be:

    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    I love Python!
    
  5. Due Date: September 16 Reading: Lab 1

    Write a program that uses the turtle library to draw a 5-pointed star.

    Your output should look like this:

    Hint: To draw the 5-pointed star, the turtle must turn a total of 720 degrees. How many degrees does the turtle need to turn at each point?


  6. Due Date: September 17 Reading: Think CS Section 4.7

    Write a program that prints out the numbers from 2 to 17.

    The output of your program should be:

    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
  7. Due Date: September 24 Reading: Lab 2

    Using the string commands introduced in Lab 2, write a Python program that prompts the user for a message, and then prints the message, the message in upper case letters, and the message in lower case letters.

    A sample run of your program should look like:

    Enter a message:  Mihi cura futuri
    Mihi cura futuri
    MIHI CURA FUTURI
    mihi cura futuri
    

    Another run:

    Enter a message:  I love Python!
    I love Python!
    I LOVE PYTHON!
    i love python!
    

    Hint: Your program should be able to take any phrase the user enters and prints it, it in upper case letters, and it in lower case letters. To do that, you need to store the phrase in a variable and print variations of the stored variable.

  8. Due Date: September 26 Reading: Lab 2

    Write a program that prompts the user to enter a phrase and then prints out the ASCII code of each character in the phrase.

    A sample run of your program should look like:

    Enter a phrase:  I love Python!
    In ASCII:
    73
    32
    108
    111
    118
    101
    32
    80
    121
    116
    104
    111
    110
    33
    

    And another sample run:

    Enter a phrase: ABC
    In ASCII:
    65
    66
    67
    

    Hint: If c is a character, ord(c) returns its ASCII code. For example, if c is 'I', then ord(c) returns 73. See Lab 2.

  9. Due Date: September 27 Reading: Lab 3

    Write a program that asks the user for the hexcode of a color and then displays a turtle that color.

    Make sure the turtle is the correct shape by including turtle.shape("turtle") in your program.

    A sample run of your program should look like:

    Enter a hex string:  #A922A9
    

    and the output should look similar to:

  10. Due Date: September 30 Reading: Lab 3

    Write a program that implements the pseudocode below:

        For i = 5, 10, 15, 20, 25, ... ,300:
            Walk forward i steps
            Turn left 91 degrees
    
    Your output should look similar to:

    Hint: See examples of range(start,stop,step) in Lab 2.


  11. Due Date: October 1 Reading: Lab 3

    Modify the program from Lab 3 to show the shades of blue.

    Your output should look similar to:

  12. Due Date: October 7 Reading: Lab 3

    Draw a cornflower blue pentagon using the turtle library. You can specify the color by name ("cornflowerblue"), by hex string ("#6495ED"), or by 255-mode values (100, 149, 237). The turtle should be turtle shaped. Your turtle should move forward 100 units, turn left the correct amount of degrees, and then stamp.

    A sample run of your program will look like:

    Hint: See Lab 3.

  13. Due Date: October 8 Reading: Lab 2

    Write a program that asks the user for a message, then prints out that message in reverse. The reversed output message should be printed with two copies of each character per line.

    A sample run of your program should look like:

    Enter a message: I love Python!
    ! !
    n n
    o o
    h h
    t t
    y y
    P P
    
    e e
    v v
    o o
    l l
    
    I I
    

    Hint: use a for-loop that starts at the last index in the string and stops at the first index in the string:

    lastIdx = len(myString) - 1
    for i in range(lastIdx, -1, -1):
      #print each character in myString, twice on each line
    

  14. Due Date: October 9 Reading: Lab 4

    Write a program that asks the user for 5 whole (integer) numbers. For each number, turn the turtle left the degrees entered and then the turtle should move forward 100.

    A sample run of your program should look like:

    Enter a number: 270
    Enter a number: 100
    Enter a number: 190
    Enter a number: 200
    Enter a number: 80
    

    and the output should look similar to:

  15. Due Date: October 15 Reading


    (The cipher disk above shifts 'A' to 'N', 'B' to 'O', ... 'Z' to 'M', or a shift of 13. From secretcodebreaker.com.)

    Write a program that prompts the user to enter a word and then prints out the word with each letter shifted right by 13. That is, 'a' becomes 'n', 'b' becomes 'o', ... 'y' becomes 'l', and 'z' becomes 'm'.

    Assume that all inputted words are in lower case letters: 'a',...,'z'.

    A sample run of your program should look like:

    Enter a word: zebra
    Your word in code is:
    mroen
    

    Hint: You can use this file to get started with this assignment.

  16. Due Date: October 16 Reading: Lab 4

    Write a program that converts kilometers to miles. Your program should prompt the user for the number of kilometers and then print out the number of miles.

    A useful formula: miles = 0.621371*kilometers.

  17. Due Date: October 22 Reading: Lab 4

    Write a program that implements the pseudocode below:

    1.  Ask the user for the number of hours until the weekend.
    2.  Print out the days until the weekend (days = hours // 24)
    3.  Print out the leftover hours (leftover = hours % 24)
    

    A sample run of your program should look like:

    Enter number of hours:  27
    Days: 1
    Hours: 3
    

    and another sample run:

    Enter number of hours:  52
    Days: 2
    Hours: 4
    

    Hint: See Section 2.7.

  18. Due Date: October 23 Reading: Lab 5

    Following Lab 5, write a program that asks the user for the name of a png file and print the number of pixels that are nearly white (the fraction of red, the fraction of green, and the fraction of blue are all above 0.75).

    For example, if your file was of the snow pack in the Sierra Nevada mountains in California in September 2014:

    then a sample run would be:

    Enter file name:  caDrought2014.png
    Snow count is 38010

    Note: for this program, you only need to compute the snow count. Showing the image will confuse the grading script, since it's only expecting the snow count.

  19. Due Date: October 28 Reading: Lab 2 and Lab 4

    We can store DNA sequences as strings. These strings are made up of the letters A, C, G, and T. For a given DNA string, the GC-content is the percent of the string that is C or G, written as a decimal.

    Write a program that prompts the user for a DNA string, and then prints the length and GC-content of that string.

    A sample run of the program:

    Enter a DNA string:  ACGCCCGGGATG
    Length is 12
    GC-content is 0.75
    

    Hint: You can use a for-loop to go through each character in the string, and count each time you encounter a 'C' or 'G'. You can use an if-statment to check what kind of character the loop is currently on. Alternatively, you can use the count() method introduced in Lab 2 to get the total occurrences of 'C' and 'G' in the string.


  20. Due Date: October 29 Burch's Logic & Circuits
    Build a circuit that has the same behavior as a nand gate (i.e. for the same inputs, gives identical output) using only and, or, and not gates.

    Save your expression to a text file. See Lab 5 for the format for submitting logical expressions to Gradescope.

  21. Due Date: October 30 Burch's Logic & Circuits

    Build a circuit that has the same behavior as a nor gate (i.e. for the same inputs, gives identical output) using only and, or, and not gates.

    Save your expression to a text file. See Lab 5 for the format for submitting logical expressions to Gradescope.

  22. Due Date: October 31 Burch's Logic & Circuits

    Write a logical expression that is equivalent to the circuit that computes the majority of 3 inputs, called in1, in2, in3:

    • If two or more of the inputs are True, then your expression should evaluate to True.
    • Otherwise (two or more of the inputs are False), then your expression should evaluate to False.

    Save your expression to a text file. See Lab 5 for the format for submitting logical expressions to Gradescope.

  23. Due Date: November 1 Reading: Lab 5

    Logical gates can be used to do arithmetic on binary numbers. For example, we can write a logical circuit whose output is one more than the inputted number. Our inputs are in1 and in2 and the outputs are stored in out1, out2, and out3.


    Here is a table of the inputs and outputs:
    InputsOutputs
    Decimal
    Number
    in1in2Decimal
    Number
    out1out2out3
    000 1001
    101 2010
    210 3011
    311 4100

    Submit a text file with each of the outputs on a separate line:

    #Name:  YourNameHere
    #Date:  October 2024
    #Logical expressions for a 4-bit incrementer
    
    out1 = ...
    out2 = ...
    out3 = ...
    
    Where "..." is replaced by your logical expression (see Lab 5).

    Note: here's a quick review of binary numbers.

  24. Due Date: November 4 Think CS: Chapter 4 & Section 7.4

    The program turtleString.py takes a string as input and uses that string to control what the turtle draws on the screen (inspired by code.org's graph paper programming). Currently, the program processes the following commands:

    • 'F': moves the turtle forward 50 steps
    • 'L': turns the turtle 90 degrees to the left
    • 'R': turns the turtle 90 degrees to the right
    • '^': lifts the pen
    • 'v': lowers the pen
    For example, if the user enters the string "FLFLFLFL^FFFvFLFLFLFL", the turtle would move forward and then turn left. It repeats this 4 times, drawing a square. Next, it lifts the pen and move forward 3, puts the pen back down and draw another square.

    Modify this program to allow the user also to specify with the following symbols:

    • 'B': moves the turtle backwards 50 steps
    • 'S': makes the turtle stamp
    • 'l': turns the turle 45 degrees to the left
    • 'r': turns the turtle 45 degrees to the right
    • 'p': change the pen color to purple
  25. Due Date: November 5 GitHub Guide

    In Lab 6, you created a GitHub account. Submit a text file with the name of your account. The grading script is expecting a file with the format:

    #Name:  Your name
    #Date:  October 2024
    #Account name for my GitHub account
    
    AccountNameGoesHere
    

    Note: it takes a few minutes for a newly created GitHub account to be visible. If you submit to Gradescope and get a message that the account doesn't exist, wait a few minutes and try again.