Worksheet For Class IX AI
Worksheet For Class IX AI
Class IX
AI
Section A: Multiple Choice Questions (MCQs)
Answer: c) str
Answer: d) class
4. What is the default value of a boolean variable in Python if not explicitly initialized?
a) True
b) False
c) None
d) 0
Answer: c) None
Answer: d) x = 10
6. What will be the output of print(5 2)?
a) 25
b) 10
c) 55
d) 52
Answer: a) 25
Answer: c) float
Answer: c) 2nd_var
10. Which of the following operators is used for integer division in Python?
a) /
b) //
c) %
d)
Answer: b) //
11. Assertion: The int data type is used to store whole numbers.
Reasoning: int can store positive and negative whole numbers.
Answer: Both Assertion and Reasoning are correct, and Reasoning is the correct explanation for
Assertion.
12. Assertion: The float data type is used for storing decimal numbers.
Reasoning: float can hold numbers with a decimal point.
Answer: Both Assertion and Reasoning are correct, and Reasoning is the correct explanation for
Assertion.
:
python
text = input("Enter a string: ")
vowels = 'aeiou'
count = 0
for char in text:
if char.lower() in vowels:
count += 1
print("Number of vowels:", count)
37. What is the difference between float and int data types?
Answer: float is used for numbers with decimal points (e.g., 3.14), while int is used for whole numbers
without decimal points (e.g., 5).
42. Write a Python program to display the current date and time.
Answer:
python
import datetime
now = datetime.datetime.now()
print("Current date and time:", now)
47. How can you remove whitespace from the beginning and end of a string?
Answer: Use the strip() method. Example: " text ".strip() returns "text".
51. Case Study: You are given a task to create a simple calculator program that performs addition,
subtraction, multiplication, and division based on user choice. Write a Python program to achieve this.
Answer:
python
print("Select operation:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
if choice == '1':
print("Result: ", num1 + num2)
elif choice == '2':
print("Result: ", num1 - num2)
elif choice == '3':
print("Result: ", num1 num2)
elif choice == '4':
if num2 != 0:
print("Result: ", num1 / num2)
else:
print("Error: Division by zero")
else:
print("Invalid Input")
52. Case Study: You need to write a program that takes a sentence from the user and counts the number
of words in it. Write a Python program to accomplish this.
Answer:
python
sentence = input("Enter a sentence: ")
word_count = len(sentence.split())
print("Number of words:", word_count)
53. Case Study: Create a Python program that calculates the factorial of a number provided by the user.
Answer:
python
number = int(input("Enter a number: "))
factorial = 1
for i in range(1, number + 1):
factorial = i
print("Factorial of", number, "is:", factorial)
54. Case Study: Develop a Python program that checks if a number is positive, negative, or zero.
Answer:
python
number = float(input("Enter a number: "))
if number > 0:
print("The number is positive.")
elif number < 0:
print("The number is negative.")
else:
print("The number is zero.")
55. Case Study: Write a Python program to find and print all prime numbers between 1 and a given
number.
Answer:
python
limit = int(input("Enter the upper limit: "))
for num in range(2, limit + 1):
is_prime = True
for i in range(2, int(num0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime:
print(num)
56. Case Study: Create a Python program that converts a given temperature in Celsius to Fahrenheit and
Kelvin.
Answer:
python
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius 9/5) + 32
kelvin = celsius + 273.15
print("Temperature in Fahrenheit:", fahrenheit)
print("Temperature in Kelvin:", kelvin)
57. Case Study: Write a Python program to display the Fibonacci sequence up to a given number of
terms.
Answer:
python
terms = int(input("Enter number of terms: "))
a, b = 0, 1
count = 0
while count < terms:
print(a)
a, b = b, a + b
count += 1
58. Case Study: Create a Python program that checks if a string is a palindrome.
Answer:
python
text = input("Enter a string: ")
reversed_text = text[::-1]
if text == reversed_text:
print("The string is a palindrome.")
else:
print("The string is not a palindrome.")
59. Case Study: Write a Python program to find the sum of all even numbers up to a given limit.
Answer:
python
limit = int(input("Enter the upper limit: "))
total_sum = 0
for num in range(2, limit + 1, 2):
total_sum += num
print("Sum of all even numbers up to", limit, "is:", total_sum)
60. Case Study: Develop a Python program that finds and displays the largest number from a list of
numbers entered by the user.
Answer:
python
numbers = [float(x) for x in input("Enter numbers separated by spaces: ").split()]
largest = max(numbers)
print("The largest number is:", largest)
Section F: Long Answer Type Question
61. What are operators in Python and what are their types?
Answer:
Operators in Python are symbols used to perform operations on variables and values. Python supports
various types of operators:
include:
- + (Addition): Adds two values. Example: 5 + 3 results in 8.
- - (Subtraction): Subtracts one value from another. Example: 5 - 3 results in 2.
- (Multiplication): Multiplies two values. Example: 5 3 results in 15.
- / (Division): Divides one value by another. Example: 5 / 3 results in 1.6667.
- // (Floor Division): Divides one value by another and returns the largest integer less than or equal
to the result. Example: 5 // 3 results in 1.
- % (Modulus): Returns the remainder of a division. Example: 5 % 3 results in 2.
- (Exponentiation): Raises one value to the power of another. Example: 5 3 results in 125.