PROGRAMMING

m9/ PYTHON
REMEMBERS




Debugging

p41 ! Syntax error refers to the structure and the rules.
 
>>> (1 + 2)  # correct
3
>>> 2)  # incorrect
# SyntaxError: invalid syntax
Runtime errors does not appear until after the program has started (also called exceptions).
 
>>> first = "Hello"
>>> second = "World"
>>> first + " " + secoend

# NameError: name 'secoend' is not defined
Semantic errors will not generate errors but it will not do the right thing.
 
# /var/www/python/calculator.py

num1 = input('Enter number 1: ')
num2 = input('Enter number 2: ')
sum = num1 + num2

print(sum)  # 12 - semantic error

# The error is that the program performs concatenation instead of addition
# The programmer failed to convert the inputs to integers

sum = int(num1) + int(num2)
print (sum)  # 3 - correct
... 3 lines
 

Questions    
Recursion

        A B C D E F
🔔
1/1