REMEMBER PYTHON

MINTE9 2REMEMBER

Last update:   25-07-2021

Debugging

p41 ! Syntax error refers to the structure and the rules.

>>> (1 + 2)  # correct
3
>>> 2)  # incorrect
# SyntaxError: invalid syntax
... 4 lines˄˄˄
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
... 4 lines˄˄˄
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
... 9 lines˄˄˄

Questions
CARD
09
32

A B C D E F
🔔
1/1