CS 61C Spring 2024 | Lab 0: Intro, Setup

216 阅读1分钟

Cloning My Repo

git clone git@github.com:61c-teach/sp24-lab-starter.git cs61c 

Exploring My Repo: Files

My labs repo structure looks like:

tree       
.
├── lab00
│   ├── code.py
│   ├── gen-debug.sh
│   ├── get-ssh-key.sh
│   └── init.sh
├── lab01
│   ├── ex1_hello.c
│   ├── ex2_pointer_basics.c
│   ├── ex3_pointers_and_functions.c
│   ├── ex4_arrays.c
│   ├── ex4_arrays_updated.c
│   ├── ex5_pointer_arithmetic.c
│   ├── ex5_pointer_arithmetic_updated.c
│   ├── ex6_strings.c
│   ├── ex7_strcpy.c
│   ├── ex7_strcpy_fixed.c
│   └── ex8_structs.c
├── README.md
└── tools
    └── download_tools.sh

4 directories, 17 files

Fuzzing and Buzzing

Use Vim to open up code.py and look through the fizzbuzz(num) function. It should:

  • Print "num: fizz" if num is a multiple of 3
  • Print "num: buzz" if num is a multiple of 5
  • Print nothing if the num is not a multiple of 3 or 5

However, if you run the program (python3 code.py), that doesn't seem to happen! Try to fix this bug by only editing the if and elif statements. After fixing the code, save, add, and commit your work using git add and git commit.

def get_airspeed_velocity_of(unladen_swallow):
  if unladen_swallow.type == "african":
    return # redacted
  elif unladen_swallow.type == "european":
    return # redacted

# pretend there's code here...

def fizzbuzz(num):
  if num == 3: # edit this line
    print(f"{num}: fizz")
  if num == 5: # edit this line
    print(f"{num}: buzz")

for i in range(1, 20):
  fizzbuzz(i)

# pretend there's code here...

My answer:

def fizzbuzz(num):
  if num % 3 == 0: # edit this line
    print(f"{num}: fizz")
  if num % 5 == 0: # edit this line
    print(f"{num}: buzz")

Commit:

git add code.py
git commit -m '(lab0) intro & setup'
git push github main:main