Table of contents | |
Multiple Choice Questions (MCQs) | |
High Order Thinking Questions (HOTS) | |
Fill in the Blanks | |
True or False | |
Hands-On Questions |
Q.1. Which of the following is not a valid variable name in Python?
(a) myVariable
(b) 123Variable
(c) _variable
(d) variable_123
Ans. (b)
Q.2. What is the correct way to declare and initialize a variable in Python?
(a) x = 5
(b) x := 5
(c) 5 = x
(d) x == 5
Ans. (a)
Q.3. Which of the following data types is immutable in Python?
(a) list
(b) dictionary
(c) tuple
(d) set
Ans. (c)
Q.4. What is the output of the following code snippet?
x = 5
y = "Hello"
print(x + y)
(a) 5Hello
(b) TypeError: unsupported operand type(s) for +: 'int' and 'str'
(c) HelloHelloHelloHelloHello
(d) Hello5
Ans. (b)
Q.5. Which operator is used for exponentiation in Python?
(a) +
(b) -
(c) *
(d) **
Ans. (d)
Q.1. Write a Python program to swap the values of two variables without using a temporary variable.
x = 5
y = 10
x, y = y, x
print("x =", x)
print("y =", y)
Q.2. Write a Python program to calculate the area of a circle given the radius (Hint: Use the math module).
import math
radius = float(input("Enter the radius: "))
area = math.pi * radius ** 2
print("Area of the circle:", area)
Q.3. Write a Python program to check if a given year is a leap year or not.
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
print(year, "is a leap year")
else:
print(year, "is not a leap year")
Q.4. Write a Python program to calculate the sum of the digits of a positive integer.
num = int(input("Enter a positive integer: "))
digit_sum = 0
while num > 0:
digit_sum += num % 10
num //= 10
print("Sum of digits:", digit_sum)
Q.5. Write a Python program to reverse a given list.
original_list = [1, 2, 3, 4, 5]
reversed_list = original_list[::-1]
print("Reversed list:", reversed_list)
Q.1. The process of assigning a value to a variable is called ________.
Ans. assignment
Q.2. In Python, the ________ function is used to convert a value to an integer.
Ans. int()
Q.3. A ________ is an ordered collection of elements, enclosed in square brackets [ ].
Ans. list
Q.4. The ________ operator returns the remainder when one number is divided by another.
Ans. % (modulo)
Q.5. The ________ statement is used to receive input from the user.
Ans. input
Q.1. In Python, variables do not need to be declared before using them.
Ans. True
Q.2. The data type of a variable in Python can be changed during the execution of the program.
Ans. True
Q.3. Python supports complex numbers as a built-in data type.
Ans. True
Q.4. The expression "5" + 3 will result in a TypeError.
Ans. True
Q.5. The len() function can be used to determine the number of elements in a list.
Ans. True
Q.1. Write a Python program to calculate the area of a rectangle. Prompt the user to enter the length and width.
length = float(input("Enter the length: "))
width = float(input("Enter the width: "))
area = length * width
print("Area of the rectangle:", area)
Q.2. Write a Python program to convert a temperature in Celsius to Fahrenheit. Prompt the user to enter the temperature in Celsius.
celsius = float(input("Enter the temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print("Temperature in Fahrenheit:", fahrenheit)
Q.3. Write a Python program to swap the values of two variables using a temporary variable.
x = 5
y = 10
temp = x
x = y
y = temp
print("x =", x)
print("y =", y)
Q.4. Write a Python program to check if a given string is a palindrome or not.
string = input("Enter a string: ")
reversed_string = string[::-1]
if string == reversed_string:
print("Palindrome")
else:
print("Not a palindrome")
Q.5. Write a Python program to find the largest element in a given list.
numbers = [5, 2, 9, 1, 7]
largest = max(numbers)
print("Largest element:", largest)
49 videos|38 docs|18 tests
|
|
Explore Courses for Software Development exam
|