0% found this document useful (0 votes)
4 views10 pages

CH 1

The document outlines various types of errors that can occur in Python programming, including syntax errors, semantic errors, runtime errors, and logical errors. It provides examples of each type of error and includes exercises for identifying and correcting errors in sample code. Additionally, it discusses mutable and immutable data types and includes worksheets for students to practice their understanding of these concepts.

Uploaded by

Orin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views10 pages

CH 1

The document outlines various types of errors that can occur in Python programming, including syntax errors, semantic errors, runtime errors, and logical errors. It provides examples of each type of error and includes exercises for identifying and correcting errors in sample code. Additionally, it discusses mutable and immutable data types and includes worksheets for students to practice their understanding of these concepts.

Uploaded by

Orin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Student Name:

Teacher Name: Jahanara Taznina Orin

Chapter 1
Errors in Python

Q. What errors can occur in the Python programming language?

1
Syntax errors:
These occur when a programmer makes mistakes in typing the code's syntax
correctly. The most commonly occurring syntax errors in Python language
are:
Example:
• Missing “)” “(”
• Missing “:”

Semantic Errors:
Semantics refers to the meaning of a statement. So, when a statement doesn’t
make any sense and is not meaningful then we can say it is a Semantic error.
For example,
a=5 #Sattement 1
b=7 #Statement 2
a+b=res #Statement 3
In the above example, we can see a syntax error but actually it is a semantic
error,

Run Time Error:


Sometimes the program is correct syntactically and semantically, but when the
programmer runs the program, errors occur. Such kinds of errors are called
runtime errors.
Runtime errors are very hard to detect in the programs. Example: can’t
perform an action on data because it is an invalid data type.

2
Logical Error:
Sometimes, we do not get the output we expected after the compilation and
execution of a program. Even though the code seems error-free, the output
generated is different from the expected one. These types of errors are called
Logical Errors.
For example, in place of addition, subtraction is done.

Other Errors

3
4
Q. Put the Tick (√) marks in an immutable datatype?

5
Q. Look at each program and identify the errors in each.
Classify them as either syntax or logic errors. Make sure you can explain
your answer and provide the corrected code.

Example
This program should divide the first number by the second

01 number1 = input(“Please enter a number”)


02 number2 = input (“Please enter another number)
03 Sum = number 1 - numBer2
04 print (Summ)

Line Error Explanation Corrected code (if needed)

02 Syntax Missing speech marks at end of number2 = input (“Please enter another
string number”)

03 Syntax Variable number1 has a space in number1


(number 1)

03 Logic Minus used instead of divide Sum = number1 / number2

03 Syntax Variable spelled incorrectly number2


(numBer2)

04 Syntax Variable spelled incorrectly Sum


(Summ)

1. Define Bug and debugging.


2. What errors can occur in the Python programming language?
3. Explain any 3 types of errors in the Python program.
4. What is the mutable and immutable datatype?
5. Write down the difference between mutable and immutable
datatype.
6. Put the Tick (√) marks in an immutable datatype?
6
International Coding and Engineering
(NICE) School & College
Worksheet
Student’s Name: Subject: Python Programming Language Date:
Teacher’s Name: Jahanara Taznina Orin Roll: Class: STD VIII

Q. Rewrite the following code in Python after removing all errors in order to get the output.
Code:
• PI=3.14
• radius = float(input("Enter the radius of the circle: ")
• area = PI * (radius * 2)
• perimeter = 2 * PI * radius
• print("Area of the circle:" area)
• print("Perimeter of the circle:",perimete)
Correct code:

output:

7
Q. totalAge = age1 + age2 + age3 + age4
numAge = 4
aveAge = totalAge/numAge
print(aveAge)

Type of error:___________________________________________________________

Q. Print "I cant't wait until Thanksgiving! I'm going to eat and eat and eat!"

Type of error:_________________________________________________________

8
NextGen International Coding and Engineering
(NICE) School & College
Worksheet

Student’s Name: Subject: Python Programming Language Date:


Teacher’s Name: Jahanara Taznina Orin Roll: Class: STD VIII
Q. Input "Please enter your groups golf scores:"
print "First score ==>", score1
print "Second score ==>", score2
print "Third score ==>", score3
print "Fourth score ==>", score4
TotalScore = score1 + score2 + score3 + score4

Type of error:_________________________________________________________

Q. PRINT I like CSC001 so much, I'm going to major in C.S.

Type of error:______________________________________________________

Q. print ("First score ==>", score1)


print ("Second score ==>", score2)
score1=18
score2=89
TotalScore = score1 + score2

Type of error:______________________________________________________

Q. Put the Tick (√) marks in immutable datatypes?

9
Q. What kind of errors do the following statements produce?
Type in the following into the SHELL: Is there an error? What is the reason?
print (hello world)
SyntaxError: invalid syntax. Perhaps you forgot a comma?

print ”hello world”

print (“hello world)

Print (“hello world”)

print (“hello world”

print (“Yo world, how is it going”)


No Error

print (“Hello World”);

Q. Look at each program and identify the errors in each.


Classify them as either syntax or logic errors. Make sure you can explain your
answer and provide the corrected code.
Example
This program should divide the first number by the second
01 number1 = input(“Please enter a number”)
02 number2 = input (“Please enter another number)
03 Sum = number 1 - numBer2
04 print (Summ)

Line Error Explanation Corrected code (if needed)

02 number2 = input (“Please enter another


number”)

03 number1

03 Sum = number1 / number2

03 number2

04 Sum

10

You might also like