Q33: Print numbers from 1 to 5 using a while loop.
Expected Output:
1
2
3
4
5
Q34: Print even numbers from 2 to 10 using a while loop.
Expected Output:
2
4
6
8
10
Q35: Print each element from a list of fruits.
Expected Output:
apple
banana
cherry
Q36: Print numbers from 1 to 5 using a for loop.
Expected Output:
1
2
3
4
5
Q37: Create a function that prints “Hello, World!”.
Expected Output:
Hello, World!
Q38: Create a function that takes a name as input and prints “Hello, !”.
Expected Output:
Hello, Om!
Q39: Use a lambda function to add two numbers.
Expected Output:
15
Q40: Use a lambda function to find the square of a number.
Expected Output:
49
Q41: Create an array of integers and print it.
Expected Output:
[1, 2, 3, 4, 5]
Q42: Access the third element of the array.
Expected Output:
3
Q43: Create a class Car with a method start() that prints “Car started”.
Expected Output:
Car started
Q44: Create a class Person with attributes name and age, then print them.
Expected Output:
Name: Om
Age: 20
Q45: Create a parent class Animal and child class Dog that inherits from it.
Expected Output:
Dog is an animal
Q46: Add a method sound() in the child class that prints “Bark”.
Expected Output:
Bark
Q47: Create an iterator for a list and print its first two items.
Expected Output:
apple
banana
Q48: Use a loop to print all elements from an iterator.
Expected Output:
apple
banana
cherry
Q49: Demonstrate a local variable inside a function.
Expected Output:
Local variable value: 10
Q50: Access a global variable from inside a function.
Expected Output:
Global variable value: Python
Q51: Import the math module and print the square root of 16.
Expected Output:
4.0
Q52: Import the random module and print a random number between 1 and 10.
Expected Output:
7
Q53: Print today’s date using the datetime module.
Expected Output:
2025-10-11
Q54: Print the current year.
Expected Output:
2025
Q55: Print the value of π using the math module.
Expected Output:
3.141592653589793
Q56: Find the factorial of 5.
Expected Output:
120
Q57: Convert a Python dictionary to a JSON string and print it.
Expected Output:
{"name": "Om", "age": 20}
Q58: Convert a JSON string to a Python dictionary.
Expected Output:
{'name': 'Om', 'age': 20}
Q59: Create a new text file and write “Hello File!”.
Expected Output:
File created successfully!
Q60: Read and print the content of the created file.
Expected Output:
Hello File!
Q61: Handle division by zero using a try-except block.
Expected Output:
Error: Division by zero not allowed
Q62: Handle invalid input with exception handling.
Expected Output:
Error: Invalid input