Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

Python Questions Answers

The document provides an overview of Python, highlighting its features such as ease of learning, extensive libraries, and community support. It explains the role of variables, built-in functions for input/output, control flow types, and operators with their precedence. Additionally, it includes examples of Python expressions, programs for summing even numbers, performing arithmetic operations, and the use of the break statement.

Uploaded by

acharvinay35
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Python Questions Answers

The document provides an overview of Python, highlighting its features such as ease of learning, extensive libraries, and community support. It explains the role of variables, built-in functions for input/output, control flow types, and operators with their precedence. Additionally, it includes examples of Python expressions, programs for summing even numbers, performing arithmetic operations, and the use of the break statement.

Uploaded by

acharvinay35
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Questions and Answers

1) Explain the features of Python that make it a popular choice for various applications.

Python is easy to learn and use, has extensive libraries, supports multiple programming paradigms,
is portable, dynamically typed, and has strong community support.

2) Describe the role of variables in Python. How are they declared and assigned values?

Variables store data. In Python, variables are created when assigned a value. Example:
x = 10
name = 'Python'
pi = 3.14

3) List and explain any 4 commonly used built-in functions in Python for console input and
output operations.

print(): Displays output


input(): Takes user input
len(): Returns length of an object
type(): Returns type of a variable

4) Differentiate between the various types of control flow in Python.

Conditional Statements (if-else), Loops (for, while), and Exception Handling (try-except) control the
flow of execution.

5) Discuss the various operators in Python and their precedence and association rules.

Python has arithmetic, comparison, logical, bitwise, and assignment operators. Precedence order:
1. Parentheses (), 2. Exponentiation **, 3. Multiplication *, 4. Addition +, 5. Comparison ==, 6.
Logical and, or.

6) Write a Python expression and calculate the result.

A=5+2*3-4/2=9
B = (4+5) * 3/2 - 1 = 12.5
C = 10/2 * 2 + 5 * 2 - 4 = 16
D = (10-3) * 2 / (5-2) = 4.67
7) Write a Python program where a user needs to find the sum of all even numbers between 1
and a given number.

num = int(input('Enter a number: '))


sum_even = sum(i for i in range(1, num + 1) if i % 2 == 0)
print('Sum:', sum_even)

8) Write a Python program to perform arithmetic operations on two variables.

a = int(input('Enter first number: '))


b = int(input('Enter second number: '))
print('Addition:', a + b)
print('Subtraction:', a - b)
print('Multiplication:', a * b)
print('Division:', a / b if b != 0 else 'Undefined')

PART-B: 1) Example of a situation where the break statement is used in Python.

for i in range(10):
if i == 5:
break
print(i) # Stops when i reaches 5

2) What is an interpreter?

An interpreter executes code line by line, unlike a compiler. Python is an interpreted language.

3) What is the purpose of the range() function in Python?

The range() function generates sequences of numbers. Example:


for i in range(1, 6): print(i) # 1 to 5

You might also like