0% found this document useful (0 votes)
12 views

Python Programming Questions and Examples Fixed

Uploaded by

mua347175
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)
12 views

Python Programming Questions and Examples Fixed

Uploaded by

mua347175
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/ 4

Programming Word Problems and Examples (Chapters 1-6)

-----------------------------------------------------

Word Problem-Based Programming Questions:

1. Write a Python program that calculates the area of a circle using a function that takes the radius

as input and returns the area.

Hint: Use the formula Area = 3.14 * r^2.

2. Develop a Python script that determines whether a number is positive, negative, or zero using

conditional statements.

3. Create a Python program that takes a list of numbers and finds the maximum value using a loop.

4. Write a function in Python that takes two lists and returns True if they share at least one common

element.

5. Write a Python program to display the multiplication table for a given number using a for loop.

6. Develop a Python program to calculate the factorial of a number using recursion.

7. Create a Python script to read a file, count the number of lines, and print the count.

8. Design a Python program that uses nested loops to display a pattern, such as a pyramid of stars

(*).
9. Write a Python function to check whether a given string is a palindrome.

10. Implement a program that handles file reading and writes content to another file, demonstrating

file I/O operations.

Examples from the Document:

1. Example: Area of a Circle

pi = 3.14

def area_of_circle(r):

return pi * r * r

r = int(input("Enter the radius: "))

print("Area:", area_of_circle(r))

2. Example: Largest of Two Numbers

def biggest(a, b):

if a > b:

return a

else:

return b

a = int(input("Enter value a: "))

b = int(input("Enter value b: "))

print("Biggest number:", biggest(a, b))

3. Example: Iteration using While Loop

count = 0
while count < 10:

print("Count:", count)

count += 1

4. Example: Checking Common Elements in Two Lists

def common_elements(list1, list2):

for x in list1:

for y in list2:

if x == y:

return True

return False

print(common_elements([1, 2, 3], [3, 4, 5])) # Output: True

5. Example: Factorial Using Recursion

def factorial(n):

if n == 1:

return 1

else:

return n * factorial(n - 1)

print(factorial(5)) # Output: 120

End-of-Chapter Programming Questions (1-6):

1. Write a Python script to demonstrate the use of lists, tuples, and dictionaries.

2. Use string slicing to extract and print specific portions of a string.

3. Write a Python function that calculates the sum of numbers in a list using a loop.
4. Create a Python program to demonstrate the usage of try-except blocks for handling exceptions.

5. Implement a program that uses the math module to calculate the square root of a number.

6. Write a Python program to read from a text file, replace specific words, and save the changes to

another file.

You might also like