Python Programming – Class Example

In this Page, We are Providing Python Programming – Class Example. Students can visit for more Detail and Explanation of Python Handwritten Notes Pdf.

Python Programming – Class Example

Class example

Till now, some basic concepts of class has been discussed. The following example “ClassExample.py” defines’a class Person, which handles name and age of multiple individuals.

class Person: 
          " " "The program handles individual's data" " "
population=0

def ___init____ ( self , Name , Age ) : 
           " " "Initializes the data." " "
          self.name=Name
          self.age=Age
          Person.population+=1

def ___del___ ( self ) : 
         " " "Deleting the data." " "
        print ( ' Record of {0} is being removed'.format(self.name)) Person.population-=1

def AgeDetails ( self ) :
         ' ' 'Age details : ' ' ' 
       print ( ' { 0 } is { 1 } years old ' . format ( self . name , self . age ) )

def Records ( cls) : 
           " " "Print number of records." " "
          print ( ' There are {0} records ' . format ( cls.population ) )

records=classmethod ( Records )

print Person . ___doc___ 
record1=Person ( ' Ram ' , 26 )
print Person.AgeDetails. ___doc___ 
record1 . AgeDetails ( )
Person.records ( ) 
record2-Person ( ' Ahmed ' , 20 )
print record2 . AgeDetails. ___doc___ 
record2 . AgeDetails ( ) 
record2 . records ( ) 
record3=Person ( ' John ' , 22 )
print Person . AgeDetails. ___doc___ 
record3 . AgeDetails ( )
Person . records ( ) 
del recordl,record2 
Person . records ( )

The output is:

The program handles individual's data 
Age details :
Ram is 26 years old 
There are 1 records 
Age details :
Ahmed is 20 years old 
There are 2 records 
Age details : 
John ih 22 years old
There are 3 records 
Record of Ram is being removed 
Record of Ahmed is being removed 
There are 1 records

Variables defined in the class definition are class variables (population is a class variable); they are shared by all instances. To create instance variables (name and age are instance variables), they can be initialized in a method, e.g. self. name=value. Both class and instance variables are accessible through the notation self. name and an instance variable hide a class variable with the same name when accessed in this way. Therefore, the class variable population is better referred to as Person. population, and not-self. population. The instance variables name and age are referred to as self. name and self. age, respectively.

The Records is a method that belongs to the class and not to the instance. This is done by using classmethod ( ) built-in function. A class method receives the class as an implicit first argument, just like an instance method receives the instance. The class method can be called either on the class (Person. records ( )) or on an instance (record2 . records ( )). The instance is ignored except for its class.

The ___doc___ attribute is used to access docstrings of class (Person. ___doc___ ) and methods (record2 . AgeDetails . __doc___).

The ___del___ ( ) method is called when an instance is about to be destroyed. This is also called a destructor.

Python Object Oriented Programming

In this Page, We are Providing Python Programming – Object Oriented Programming. Students can visit for more Detail and Explanation of Python Handwritten Notes Pdf.

Python Programming – Object Oriented Programming

Object-oriented programming (OOP) is a programming paradigm that represents concepts as “objects”, that have attributes that describe the object in the form of data attributes and associated procedures known as methods. As mentioned in chapter 1, Python is an OOP language. In Python, class form the basis of OOP. Some of the features of OOP language are:

  • Inheritance
  • Polymorphism
  • Encapsulation

Some of the advantages of the OOP approach are:

– Reusability: A part of a code can be reused for accommodating new functionalities with little or no changes.
– Maintenance: If some modification is made in the base class, the effect gets reflected automatically into the derived class, thus, the code maintenance is significantly less hectic.
– Faster output: With organized and methodical coding, there is little room for error, and as a result programmer can work comfortably, resulting in fast and efficient output.

Method object

In the MyClass example, x. f is a method object and x. f ( ) returns the string ‘hello world’. The call x. f ( ) is exactly equivalent to MyClass . f (x). In general, calling a method with a list of n arguments is equivalent to calling the corresponding function with an argument list that is created by inserting the method’s object before the first argument

>>> x . f ( )
' hello world '
>>> x . f ( )==MyClass . f ( x )
True

The method object can be stored and can be called later.

>>> xf=x . f 
>>> print xf ( )
hello world
>>> type ( xf )
<type ' instancemethod ' >

Python Programming OOP

CBSE Class 12 Computer Science Python Syllabus 2021 | Check 12th CBSE Computer Science Python Exam Pattern & How to Download easily?

CBSE Class 12 Computer Science Python Syllabus

CBSE Class 12th Computer Science Syllabus 2021 Free Download: Central Board of Secondary Education (CBSE) released the new and revised Computer Science Python Syllabus for Class 12 students (reduced by 30%) 2021. The deleted syllabus of class 12th CBSE Computer Science python is given here in a detailed way along with the latest syllabus 2021-2022.

So, students are urged to check the Revised CBSE 12th Computer Science Syllabus 2021 & kickstart their preparation for future CBSE Class 12 board exams. Below we have also provided some useful links to access and score well in the upcoming CBSE 12th Computer Science Board Exam 2021. Also, check out the detailed steps on how to download the CBSE Class 12 Computer Science Syllabus 2021 from the official site by heading to the below modules.

Click Here To Download CBSE 12th Computer Science Python Syllabus 2021

CBSE Class 12 Computer Science Python Syllabus 2021-22 (New)

For perfect CBSE 12th Board Exam Preparation, you should have to be familiar with the latest and revised CBSE Class 12 Computer science python syllabus and then need to gather the best books and study resources. Here we have provided the unit-wise syllabus of computer science for cbse class 12 students. Access them online and offline by downloading the latest CBSE Syllabus for Class 12 computer science 2021-2022 from the above link and below topics text.

Unit I: Computational Thinking and Programming – 2 – (80 Theory + 70 Practical)

  • Revision of the basics of Python
  • Functions: scope, parameter passing, mutable/immutable properties of data objects, pass arrays to functions, return values, functions using libraries: mathematical, and string functions.
  • File handling: open and close a file, read, write, and append to a file, standard input, output, and error streams, relative and absolute paths.
  • Using Python libraries: create and import Python libraries
  • Recursion: simple algorithms with recursion: factorial, Fibonacci numbers; recursion on arrays: binary search
  • Idea of efficiency: performance defined as inversely proportional to the wall clock time, count the number of operations a piece of code is performing, and measure the time taken by a program. Example: take two different programs for the same problem, and understand how the efficient one takes less time.
  • Data visualization using Pyplot: line chart, pie chart, and bar chart.
  • Data structures: lists, stacks, queues.

Unit 2: Computer Networks (CN) – (30 Theory + 10 Practical)

  • Structure of a network: Types of networks: local area and wide area (web and internet), new technologies such as cloud and IoT, public vs. private cloud, wired and wireless networks; concept of a client and server.
  • Network devices such as a NIC, switch, hub, router, and access point.
  • Network stack: amplitude and frequency modulation, collision in wireless networks, error checking, and the notion of a MAC address, main idea of routing.
  • IP addresses: (v4 and v6), routing table, router, DNS, and web URLs, TCP: basic idea of retransmission, and rate
    modulation when there is congestion (analogy to a road network), Protocols: 2G, 3G, 4G, WiFi. What makes a protocol have a higher bandwidth?
  • Basic network tools: traceroute, ping, ipconfig, nslookup, whois, speed-test.
  • Application layer: HTTP (basic idea), working of email, secure communication: encryption and certificates (HTTPS), network applications: remote desktop, remote login, HTTP, FTP, SCP, SSH, POP/IMAP, SMTP, VoIP, NFC.

Unit 3: Data Management (DM-2) – (20 Theory + 20 Practical)

  • Write a minimal Django based web application that parses a GET and POST request, and writes the fields to a file – flat file and CSV file.
  • Interface Python with an SQL database
  • SQL commands: aggregation functions – having, group by, order by.

Unit 4: Society, Law, and Ethics (SLE-2) – (10 Theory)

  • Intellectual property rights, plagiarism, digital rights management, and licensing (Creative Commons, GPL, and Apache), open source, open data, privacy.
  • Privacy laws, fraud; cyber-crime- phishing, illegal downloads, child pornography, scams; cyber forensics, IT Act, 2000.
  • Technology and society: understanding of societal issues and cultural changes induced by technology.
  • E-waste management: proper disposal of used electronic gadgets.
  • Identity theft, unique ids, and biometrics.
  • Gender and disability issues while teaching and using computers.

Do Refer: Python Programs for Class 12

Deleted Syllabus of Class 12 Computer Science Python CBSE

Unit I: Computational Thinking and Programming – 2

● Recursion – simple algorithms with recursion: print a message forever, the sum of the first n natural numbers, factorial, Fibonacci numbers, recursion on arrays: binary search
● The idea of efficiency: performance measurement in terms of the number of operations.
● Data-structures: Lists as covered in Class XI, Stacks – Push, Pop using a list, Queues – Insert, Delete using a list. (One of the data structures Stack or Queue. Note: While setting the question paper a student will have an option between Stack and Queue.)

Unit II: Computer Networks

● Web Scripting Client-side (VB Script, JavaScript, PHP) and Server-side (ASP, JSP, PHP), Web 2.0 (for social networking)
● E-commerce payment transactions using online banking, mobile banking, payment apps, and services.

Unit III: Database Management

CREATE TABLE, DROP TABLE, ALTER TABLE, UPDATE ….SET, INSERT, DELETE

1. Suggested Practical List: Python Programming

● Recursively find the factorial of a natural number
● Write a recursive code to find the sum of all elements of a list.
● Write a recursive code to compute the nth Fibonacci number

CBSE 12th Class Computer Science Exam Pattern 2021

Marking Scheme plays a vital role in exam preparation time. It covers all required details about the question paper like how many marks each question carries and many more. From the below tabulated CBSE Class 12 Computer Science Python Exam Pattern 2021, you can easily understand which chapter contains a number of marks and the total number of marks to be gained by the students in the examination.

Chapter Name Theory marks Theory periods Practical periods
Computational Thinking and Programming – 2 40 70 50
Computer Networks 10 15
Database Management 20 25 20
TOTAL 70 110 70

12th CBSE Computer Science Practical Exam Pattern & Syllabus

Students of class 12 should aware of the practical exam pattern and provided important lab syllabus topics before they start preparing for the cbse class 12 computer science board exams.

Area Marks Allotted
Lab Test 12
Report file 7
Project 8
Viva voce 3
Total Marks 30

A few of the sample lab assignments are listed below:

Python Programming:

  • Recursively find the factorial of a natural number.
  • Write a recursive code to find the sum of all elements of a list.
  • Write a recursive code to compute the nth Fibonacci number.
  • Read a text file line by line and display each word separated by a #.
  • Read a text file and display the number of vowels/ consonants/ uppercase/ lowercase characters in the file.
  • Create a binary file with a name and roll number. Search for a given roll number and display the name, if not found display the appropriate message.
  • Create a binary file with roll numbers, names, and marks. Input a roll number and update the marks.
  • Remove all the lines that contain the character `a’ in a file and write it to another file.
  • Write a random number generator that generates random numbers between 1 and 6 (simulates a dice).
  • Write a Python program to implement a stack and queue using a list data-structure.
  • Take a sample of ten phishing e-mails (or any text file) and find the most commonly occurring word(s)

Database Management

  • Create a student table and insert data. Implement the following SQL commands on the student table:
  • ALTER table to add new attributes / modify data type / drop attribute
  • UPDATE table to modify data
  • ORDER By to display data in ascending/descending order DELETE to remove tuple(s)
  • GROUP BY and find the min, max, sum, count, and average
  • A similar exercise may be framed for other cases.
  • Integrate SQL with Python by importing the MySQL module.

Computer Science Project for CBSE Class XII

The aim of the class project is to create something that is tangible and useful. This should be done in groups of 2 to 3 students, and should be started by students at least 6 months before the submission deadline. The aim here is to find a real world problem that is worthwhile to solve. Students are encouraged to visit local businesses and ask them about the problems that they are facing. For example, if a business is finding it hard to create invoices for filing GST claims, then students can do a project that takes the raw data (list of transactions), groups the transactions by category, accounts for the GST tax rates, and creates invoices in the appropriate format. Students can be extremely creative here. They can use a wide variety of Python libraries to create user friendly applications such as games, software for their school, software for their disabled fellow students, and mobile applications, Of course to do some of this projects, some additional learning is required; this should be encouraged. Students should know how to teach themselves.

If three people work on a project for 6 months, at least 500 lines of code is expected. The committee has also been made aware about the degree of plagiarism in such projects. Teachers should take a very strict look at this situation, and take very strict disciplinary action against students who are cheating on lab assignments, or projects, or using pirated software to do the same. Everything that is proposed can be achieved using absolutely free, and legitimate open-source software.

How to download CBSE 12th Class Computer Science Syllabus 2021?

Students who want to download the revised CBSE 12th Class Computer Science Python Syllabus 2021 from the official website should follow the steps furnished below and get a pdf formatted 12th Computer Science syllabus 2021-2022.

  • Step 1 – Open the official website of CBSE ie., cbseacademic.nic.in.
  • Step 2 – After entering the home page, tap the ‘Senior secondary curriculum (XI-XII)’ menu.
  • Step 3 – Now, select ‘Academic Electives – (Group-A)’ option and then choose the ‘Computer Science New XII’
  • Step 4 – Once you choose that option, you will be available with the CBSE Class 12 Computer Science Syllabus 2021 to download for free in PDF. So, download and save it for further reference.

FAQs on CBSE Syllabus for Class 12 Computer Science Python 2021

1. How many units are there in the Class 12 CBSE Computer Science Python Syllabus?

Basically, there are four units that include sub-topics of computer science python in the CBSE Class 12 Computer Science Python Syllabus.

2. Is there any reduced syllabus in CBSE 12th Computer Science Syllabus 2021?

Yes, there is a 30% reduction of the syllabus for the academic year 2021-2022. So, you have to check the deleted syllabus of CBSE Class 12 Computer Science Python from our site before preparation.

3. How to download CBSE Syllabus for Class 12 Computer Science 2021 in PDF?

Just by clicking on the link provided in the above article, you can download CBSE Syllabus for Class 12 Computer Science 2021 in PDF format for free of cost.

4. What is the distribution of marks in the CBSE 12th Computer Science 2020-21 Syllabus?

The marks distribution for CBSE 12th Computer Science 2020-21 Syllabus is as follows:

I. Computational Thinking and Programming 2 – 40 Marks,
II. Computer Networks- 10 Marks and
III. Database Management -20 Marks

Python Interview Questions on Operators in Python

We have compiled most frequently asked Python Interview Questions which will help you with different expertise levels.

Python Interview Questions on Operators in Python

What are operators?
Operators are required to perform various operations on data. They are special symbols that are required to carry out arithmetic and logical operations. The values on which the operator operates are called operands.
So, if we say 10/5=2
Here 7’ is the operator that performs division and 10 and 5 are the operands. Python has the following operators defined for various operations:

  1. Arithmetic Operators
  2. Relational Operators
  3. Logical/Boolean Operators
  4. Assignment Operators
  5. Bitwise Operators
  6. Membership Operators
  7. Identity Operators

Question 1.
What are Arithmetic Operators? What are various types of arithmetic operators that we can use in Python?
Answer:
Arithmetic operators are used to performing mathematical functions such as addition, subtraction, division, and multiplication. Various types of Arithmetic operators that we can use in Python are as follows:

‘+’for Addition

>>> a = 9
>>> b = 10
>>> a + b
19
>>>

‘-’ for Subtraction

>>> a = 9
>>>b = 10
>>> a - b
-1
>>>

‘*’ for Multiplication

>>> a = 9
>>> b = 10
>>> a * b
90
>>>

‘/’ for division

>>> a = 9
>>> b = 10
>>> a/b
0.9
>>>

“%’ for Modulus – provides the value of the remainder

>>> a = 9
>>> b = 10
>>> a % b
9
>>> a = 11
>>> b = 2
>>> a % b
1
>>>

‘//’ for Floor division – a division of operands, provides integer value of quotient. The value after decimal points is removed.

>>> a = 9
>>> b = 10
>>> a // b
0
>>> a = 11
>>> b = 2
>>> a // b
5
>>>

‘**’ for finding Exponential value

>>> a = 2
>>> b = 3
>>> a**b
8
>>>b**a
9
>>>

Question 2.
What is the Arithmetic operator’s precedence in Python?
Answer:
When more than one arithmetic operator appears in an expression the operations will execute in a specific order. In Python, the operation precedence follows as per the acronym PEMDAS.
Parenthesis
Exponent
Multiplication
Division
Addition
Subtraction
(2+2)/2-2*2/(2/2)*2
= 4/2 -4/1*2
= 2-8
= -6
>>> (2+2)/2-2*2/(2/2)*2
-6.0

Question 3.
a = 2, b =4, c = 5, d = 4 Evaluate the following keeping Python’s precedence of operators:

  1. a+b+c+d
  2. a+b*c+d 4
  3. a/b+c/d
  4. a+b*c+a/b+d

Answer:

>>> a=2
>>> b=4
>>> c=5
>>> d=4
>>> a+b+c+d
15
>>> a+b*c+d
26
>>> a/b+c/d
1.75
>>> a+b*c+a/b+d
26.5
>>>

Question 4.
What are relational operators?
Answer:
Relational operators are also known as conditional or comparison operators. Relational operators in Python are defined as follows:

  1. ==: returns true if two operands are equal
  2. !=: returns true if two operands are not equal
  3. >: returns true if the left operand is greater than the right operand
  4. <: returns true if the left operand is smaller than the right operand
  5. >=: returns true if the left operand is greater than or equal to the right operand
  6. <=: returns true if the left operand is smaller or equal to the right operand
>>> a = 5
>>> b = 6
>>> c = 7
>>> d = 7
>>> a == b
False
>>> c == d
True
>>> a ! = b
True
>>> c ! = d
False
>>>
>>> a > b
False
>>> a < b
True
>>> a>=b
False
>>> c>=d
True
>>> a<=b
True
>>> c<=d
True

Question 5.
a = 5, b = 6, c =7, d=7 What will be the outcome for the following:

  1. a<=b>=c
  2. -a+b==c>d
  3. b+c==6+d>=13

Answer:

>>> a<=b>=c
False
>>> -a+b==c>d
False
>>> b+c==6+d>=13
True
>>>

Question 6.
What are assignment operators?
Answer:
Assignment operators are used for assigning values to variables. Various types of assignment operators are as follows:

  1. =: a = 5 means that a is assigned value of 5
  2. += a += 5 is same as a = a+5
  3. -=: a -= 5 is same as a = a – 5
  4. *=. a *= 5 js same as a = a * 5
  5. /=: a /= 5 is same as a = a/5
  6. %=: a %=5 is same as a = a%5
  7. //=: x //= 5 is same as x= x//5
  8. **=• x **=5 js same as x = x**5
  9. &=: x &= 5 is same as x = x&5
  10. |=: x |= 5 is same as x = x|5
  11. A=: x A= 5 is same as x = xA5
  12. >>=: x >>= 5 is same as x = x>>5
  13. <<=: x <<= 5 is same as x = x<<5

Question 7.
Is a = a*2+6 same as a *= 2 + 6?
Answer:
No, a = a*2+6 is not same as a *= 2 + 6 this is because assign operator have lower precedence than the addition operator. So, if a = 5 then,
a = a *2+6 => a = 16
a *= 2 + 6 => a = 40

>>> a = 5
>>> a = a *2+6
>>> a
16
>>> a = 5
>>> a*= 2+6
>>> a
40
>>>

Question 8.
What are logical operators?
Answer:
Logical operators are generally used in control statements like if and while. They are used to control program flow. The logical operator evaluates a condition and returns “True” or “False” depending on whether the condition evaluates to True or False. Three logical operators in Python are as follows:

  • ‘and’
  • ‘or’ and
  • ‘not’
>>> a = True
>>> b = False
>>> a and b
False
>>> a or b
True
>>> not a
False
>>> not b
True
>>>

Question  9.
What are membership operators?
Answer:
The membership operators are used to check if a value exists in a sequence or not.
Two types of membership operators are as follows:

  1. in: returns true if a value is found in a sequence
  2. not in: returns true if a value is not found in a sequence
>>> a = "Hello World"
>>> "h" in a
False
>>> "h" not in a
True
>>> "H" not in a
False
>>>

Question 10.
What are bitwise operators?
Answer:
Bitwise operators work on bits and perform bit-by-bit operations. In Python, the following bit-wise operations are defined:
1. AND – &
2 & 3
2
2. OR-|
2|3
3
3. One’s complement – ~
>>> ~2
-3
4. XOR -∧
2∧3
1
5. Right shift ->>
2>>2
0
6. Left shift -<<
2<<2
8

Question 11.
What are identity operators?
Answer:
Identity operators are used to verifying whether two values are on the same part of the memory or not. There are two types of identity operators:

  1. is: return true if two operands are identical
  2. is not: returns true if two operands are not identical
>>> a = 3
>>> id(a)
140721094570896
>>> b = 3
>>> id (b)
140721094570896
>>> a is b
True
>>> a = 3
>>> b = 6
>>> c = b - a
>>> id(c)
140721094570896
>>> a is c
True
>>> a = 4
>>> b = 8
>>> a is b
False
>>> a is not b
True
>>>

Question 12.
What is the difference between a = 10 and a= = 10?
Answer:
The expression a = 10 assigns the value 10 to variable a, whereas a == 10 checks if the value of a is equal to 10 or not. If yes then it returns ‘Ti^te’ else it will return ‘False’.

Question 13.
What is an expression?
Answer:
A logical line of code that we write while programing, is called expressions. An expression can be broken into operator and operands. It is therefore said that an expression is a combination of one or more operands and zero or more operators that are together used to compute a value.
For example:
a = 6
a + b = 9
8/7

Question 14.
What are the basic rules of operator precedence in Python?
Answer:
The basic rule of operator precedence in Python is as follows:

  1. Expressions must be evaluated from left to right.
  2. Expressions of parenthesis are performed first.
  3. In Python the operation precedence follows as per the acronym PEMDAS:
  • Parenthesis
  • Exponent
  • Multiplication
  • Division
  • Addition
  • Subtraction

4. Mathematical operators are of higher precedence and the Boolean operators are of lower precedence. Hence, mathematical operations are performed before Boolean operations.

Question 15.
Arrange the following operators from high to low precedence:

  1. Assignment
  2. Exponent
  3. Addition and Subtraction
  4. Relational operators
  5. Equality operators
  6. Logical operators
  7. Multiplication, division, floor division, and modulus

Answer:
The precedence of operators from high to low is as follows:

  1. Exponent
  2. Multiplication, division, floor division, and modulus
  3. Addition and subtraction operators
  4. Relational operators
  5. Equality operators
  6. Assignment operators
  7. Logical Operators

Question 16.
Is it possible to change the order of evaluation in an expression?
Answer:
Yes, it is possible to change the order of evaluation of an expression. Suppose you want to perform addition before multiplication in an expression, then you can simply put the addition expression in parenthesis.
(2+4)*4

Question 17.
What is the difference between implicit expression and explicit expression?
Answer:
Conversion is the process of converting one data type into another. Two types of conversion in Python are as follows:

  1. Implicit type conversion
  2. Explicit type conversion

When Python automatically converts one data type to another it is called implicit conversion.

>>> a = 7
>>> type(a)
Cclass 'int'>
>>> b = 8.7
>>> type(b)
<class 'float'>
>>> type(a+b)
<class 'float' >
>>>

Explicit conversion is when the developer has to explicitly convert datatype of an object to carry out an operation.

>>> c = "12"
>>> type(c)
<class 'str'>
>>> d = 12
# addition of string and integer will generate error
>>> c+d
Traceback (most recent call last):
File "<pyshell#43>", line 1, in <module> c+d
TypeError: can only concatenate str (not "int") to str
# convert string to integer and then add
>>> int (c) +d 24
# convert integer to string and then perform concatenation
>>> c+str(d)
'1212'
>>>

Question 18.
What is a statement?
Answer:
A complete unit of code that a Python interpreter can execute is called a statement.

Question 19.
What is an input statement?
Answer:
The input statement is used to get user input from the keyboard. The syntax for input() function is as follows:
input(prompt)
The prompt is a strong message for the user.

>>> a = input ("Please enter your message here :")
Please enter your message here: It is a beautiful
day
>>> a
' It is a beautiful day'
>>>

Whenever an input function is called, the program comes on hold till an input is provided by the user. The input( ) function converts the user input to a string and then returns it to the calling program.

Question 20.
Look at the following code:

num1 = input ("Enter the first number: ")
num2 = input("Enter the second number: ")
print(num1 + num2)

When the code is executed the user provides the following values:
Enter the first number: 67 Enter the second number: 78 What would be the output?
Answer:
The output will be 6778. This is because the input() function converts the user input into a string and then returns it to the calling program. So, even though the users have entered integer values, the input() function has returned string values ‘67’ and ‘78’ and the ‘+’ operator concatenates the two strings giving ‘6778’ as the answer. To add the two numbers they must be first converted to an integer value. Hence, the code requires slight modification:

num1 = input ("Enter the first number: ")
num2 = input("Enter the second number: ")
print(int(num1) + int(num2))

Output:

Enter the first number: 67
Enter the second number: 78
145
>>>

Question 21.
What is the Associativity of Python Operators? What are non-associative operators?
Answer:
Associativity defines the order in which an expression will be evaluated if it has more than one operator having the same precedence. In such a case generally left to right associativity is followed.
Operators like assignment or comparison operators have no associativity and are known as Nonassociative operators.