This document contains an assignment for a programming class at Kalyani Government Engineering College. The assignment includes questions about arithmetic operators in Python with examples, the role of indentation in Python with a supporting code example, and writing programs to calculate the area of shapes, swap numbers without a temporary variable, and explain if/elif conditions with an example. It provides the student's responses to each question that demonstrates their understanding.
This document contains an assignment for a programming class at Kalyani Government Engineering College. The assignment includes questions about arithmetic operators in Python with examples, the role of indentation in Python with a supporting code example, and writing programs to calculate the area of shapes, swap numbers without a temporary variable, and explain if/elif conditions with an example. It provides the student's responses to each question that demonstrates their understanding.
This document contains an assignment for a programming class at Kalyani Government Engineering College. The assignment includes questions about arithmetic operators in Python with examples, the role of indentation in Python with a supporting code example, and writing programs to calculate the area of shapes, swap numbers without a temporary variable, and explain if/elif conditions with an example. It provides the student's responses to each question that demonstrates their understanding.
Explain with example. b) What is the role of indenta on in python? Provide example to support your answer
Ans- a) Arithme c Operators in Python:
i) Addi on (+): Add two Operands Example:
ii) Subtrac on: Subtracts the right operand from le operand Example: iii) Mul plica on: mul ply two operands Example:
iv) Division: Divides the le operand by the right
operand. Note that in Python 3, this operator always returns a floa ng-point number. Example:
v) Floor Division: (//) Similar to the division but it
returns the largest integer less than or equal to the result Example: vi) Modulus: % Returns the remainder of the division of the le operand by the right operand. Example:
vii) Exponen a on: (**) raises the le operand to
the power of right operand Example: b) What is the role of indenta on in python? Provide example to support your answer Ans- In Python indenta on is very important. For most of language like c++, c indenta on is a ma er of style but for python it is not like that. If you don’t use proper indenta on, it will give you error. Python uses indenta on to indicate the grouping of statements. Indenta on is crucial for the proper structure and execu on of Python code.
Block Structure: In python indenta on is used to define the
block structure of code such as loops, condi onal statement, func on defini on Blocks of code with the same level of indenta on are considered part of the same block or scope.
Readability: Python relies on indenta on to make the
code more readable. It enforces a consistent and visually clear way of represen ng the structure of the code, promo ng a clean and organized coding style. Example:
2 a) Write a python program to calculate the area of
rectangle and circle and print the result. Take input from user (length, breadth and radius). b) Write a python program to swap two numbers without temporary variable. c) Explain if-elif condi on. When do we use it? Explain with example. Ans- a) area of rectangle and Circle:
b) Swap two variable without using third variable:
c) If-elif condi on in python is used to handle mul ple condi on in a more structured way. It allows you to check mul ple condi on sequen ally and execute the block of code associated with the first condi on that evaluates to True. If none of the condi ons is true, an op onal else block can be executed. ii) We would use if-elif statements when we have a series of condi ons that are mutually exclusive, meaning that only one of them should be true, and we want to execute a corresponding block of code based on which condi on is sa sfied.