Session 19 – PRP Workshop (Sec Y)
Python Data Types
1. What are the sequence data types available in Python? How to perform
slicing of a sequence data type? Give an example.
2. What is the difference between a for loop and a while in Python?
3. What is the purpose of the operators below using an example.
o
is (Hint: identity)
o
==
4. What is type casting in Python? Explain how to convert one data type into
another, e.g., int(), str(), float().
5. How do you check the type of an object/variable in Python?
6. What is a dictionary in Python? Explain when they are useful.
Python Operators
7. What are the different types of operators in Python? Discuss arithmetic,
comparison, logical, assignment, bitwise, membership, and identity operators.
8. How does the += operator work in Python?
9. Write any 4 built-in functions supported by Python for Lists based operations.
Give an example for each.
10. How does the // (floor division) operator work in Python?
11. Explain the difference between / (true division) and // (floor division).
12. What is the use of break in Python? Give an example.
13. How does the in operator work in Python? Explain its usage with sequences
like lists, tuples, strings, and dictionaries
# Find the error in the following codes.
# Write a brief comment identifying the cause of the error
# Modify the code to fix the error
# Q1
a = 100
print("a value = ", a++) # Expected output is 101
# Q2
a = 100
print("a value = ", a++)
# Q3
a = 100
printf("a value = ", a++)
# Q4
a = 100
printf("a value = "a)
# Q5
a = input("Enter number:")
b=a+1
# Q6
a = input("Enter number:")
b=a[-10]
print(b)
# Q7
a = int(input("Enter number:"))
b=a[-1]
print(b)
# Q8
a = 3
b and = 0
print(b)
Python Conditionals
# 1. Write a Python program to check whether a given number is
divisible by 13 or not.
# 2. Write a Python program to check whether or not the given
number is greater than 50. If the number is greater than 50, then
print the square root of the number.
# Find the error in the following codes.
# Write a brief comment identifying the cause of the error
# Modify the code to fix the error
Python Loops
# Q1
while(True)
print("Hello")
# Q2
for i in range():
print(i)
# Q3
for i in range(2.8,1.5):
print(i)
# Q4
a = 15
while (a>15):
a-=1
# Q5
a = 10
while (a<15):
passed
# Q6
a = 10
if (a):
print("1")
else:
print("2")
elif(a==1):
print("3")
# Q7
a = [1 2 3]
while (a):
print(a)
# Q8
a = (1 2 3)
while (a):
print(a)
# Q9
a = ""
b = a * 3.8
if (b):
print("hello")
# Q10
a = "x"
b = list(a + "3")
for i in b:
print("hello")
Python Functions
# 1. Write a Python program to print the statement
#
"Sample program" for n times
# 2. Write a python program to print the multiplication table
#
of a given number by using user-defined function.
# 3. Write a python program to swap two numbers by using userdefined function.
# 4. Write a python program to find the sum, mean and mode of the
elements of an array of numbers by using user-defined function.
# 5. Write a python program to find reverse of a number by using
user-defined function.
# 6. Write python code to find the second maximum number among
five numbers entered by user.