CPSC120A
Fundamentals of Computer Science I

Activity 4

Exploring programming errors and debugging code in broken code.

Debugging

Writing code that has errors in it is surprisingly easy to do. More often than not, your initial try at writing a solution to code is going to have some errors in them. The process of finding and eliminating these errors is called debugging. While this process seems pretty daunting, it can be an incredibly rewarding experience when you finally find your bugs.

1: 1s_place = 2
2: 10s_place = 4
3: whole_value = 10s_place * 10 + 1s_place
4: print(whole_value)
  1. Are there any Syntax or Runtime errors in the above Python program? Circle the syntax and runtime errors that exist.
  2. Fix the Syntax and Runtime errors if there are any. What does the print statement on line 4 print?
  3. Are there any Semantic errors in the above Python program? Fix the semantic errors if there are any.
1: whole_number = 1337
2: ones_digit = whole_number % 10
3: tens_digit = whole_number % 100
4: hundreds_digit = whole_number % 1000
5: thousands_digit = whole_number % 10000
6: print(whole_number, 'reversed is', ones_digit, tens_digit, hundreds_digit, thousands_digit)
  1. Are there any Syntax or Runtime errors in the above Python program? Circle the syntax and runtime errors that exist.
  2. Fix the Syntax and Runtime errors if there are any. What does the print statement on line 6 print?
  3. Are there any Semantic errors in the above Python program? Fix the semantic errors if there are any.