[go: up one dir, main page]

0% found this document useful (0 votes)
20 views12 pages

Worksheet For Class IX AI

worksheet for class ix ai

Uploaded by

tarunsharma.cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views12 pages

Worksheet For Class IX AI

worksheet for class ix ai

Uploaded by

tarunsharma.cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Worksheet

Class IX
AI
Section A: Multiple Choice Questions (MCQs)

1. Which of the following is a Python operator?


a) +
b)
c) -
d) All of the above

Answer: d) All of the above

2. Which data type is used to store a sequence of characters in Python?


a) int
b) float
c) str
d) bool

Answer: c) str

3. Which of the following is a reserved keyword in Python?


a) variable
b) print
c) function
d) class

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

5. Which of the following is used to create a variable in Python?


a) var x
b) int x
c) x =
d) x = 10

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

7. What is the type of the variable x if x = 3.14?


a) int
b) str
c) float
d) bool

Answer: c) float

8. Which of the following is not a valid identifier in Python?


a) my_var
b) _var
c) 2nd_var
d) var2

Answer: c) 2nd_var

9. What does the type() function do?


a) Converts a variable to a different type
b) Returns the type of the variable
c) Creates a new type
d) Deletes a variable

Answer: b) Returns the type of the variable

10. Which of the following operators is used for integer division in Python?
a) /
b) //
c) %
d)

Answer: b) //

Section B: Assertion and Reasoning Questions

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.

13. Assertion: In Python, print() is a keyword.


Reasoning: print is a built-in function but not a keyword.
Answer: Assertion is incorrect, but Reasoning is correct.

14. Assertion: Python keywords can be used as variable names.


Reasoning: Keywords have special meanings in Python and cannot be used as variable names.
Answer: Assertion is incorrect, but Reasoning is correct.

15. Assertion: // operator performs floor division in Python.


Reasoning: // returns the largest integer less than or equal to the result of the division.
Answer: Both Assertion and Reasoning are correct, and Reasoning is the correct explanation for
Assertion.

Section C: Short Answer Type Questions

16. What are operators in Python?


Answer: Operators are symbols used to perform operations on variables and values. Examples include
+, -, , /, , and //.

17. What is a data type?


Answer: A data type is a classification that specifies which type of value a variable can hold, such as
integer (int), floating-point number (float), string (str), or boolean (bool).

18. List any three keywords in Python.


Answer: Examples of Python keywords are if, else, while, for, and def.

19. Write a Python program to find the greatest of three numbers.


Answer:
python
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))

if num1 > num2 and num1 > num3:


print("The greatest number is:", num1)
elif num2 > num3:
print("The greatest number is:", num2)
else:
print("The greatest number is:", num3)

20. What is a variable in Python?


Answer: A variable is a name that refers to a value stored in memory. For example, x = 10 assigns the
value 10 to the variable x.
21. How do you declare a variable in Python?
Answer: Declare a variable by assigning a value to it. Example: name = "Alice"

22. Write a Python program to convert a string to uppercase.


Answer:
python
text = "hello world"
print(text.upper())

23. What will be the output of print("Python" 2)?


Answer: PythonPython

24. How do you get the length of a string in Python?


Answer:
python
text = "Hello"
length = len(text)
print(length)

25. Write a Python program to check if a number is even or odd.


Answer:
python
num = int(input("Enter a number: "))
if num % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")

Section D: Long Answer Type Questions

26. Write a Python program to calculate the area of a circle.


Answer:
python
import math

radius = float(input("Enter the radius of the circle: "))


area = math.pi (radius 2)
print("The area of the circle is:", area)

27. Explain the difference between = and == in Python.


Answer: = is used for assignment, i.e., assigning a value to a variable (e.g., x = 10). == is used for
comparison to check if two values are equal (e.g., x == 10).
28. Write a Python program to calculate the perimeter of a rectangle.
Answer:
python
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
perimeter = 2 (length + width)
print("The perimeter of the rectangle is:", perimeter)

29. Write a Python program to convert Fahrenheit to Celsius.


Answer:
python
fahrenheit = float(input("Enter temperature in Fahrenheit: "))
celsius = (fahrenheit - 32) 5/9
print("Temperature in Celsius:", celsius)

30. How can you check the type of a variable in Python?


Answer:
python
x=5
print(type(x))

31. Write a Python program to find the average of three numbers.


Answer:
python
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
average = (num1 + num2 + num3) / 3
print("The average is:", average)

32. Explain how to concatenate strings in Python.


Answer: Use the + operator to concatenate strings. Example: "Hello" + " World" results in "Hello
World".

33. Write a Python program to find the square root of a number.


Answer:
python
import math

number = float(input("Enter a number: "))


sqrt = math.sqrt(number)
print("The square root is:", sqrt)
34. What is the purpose of the print() function in Python?
Answer: The print() function displays the specified message or value on the screen.

35. Write a Python program to count the number of vowels in a string.


Answer

:
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)

36. Write a Python program to find the maximum of two numbers.


Answer:
python
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
if num1 > num2:
print("The maximum number is:", num1)
else:
print("The maximum number is:", num2)

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).

38. Write a Python program to swap the values of two variables.


Answer:
python
a = input("Enter value of a: ")
b = input("Enter value of b: ")
a, b = b, a
print("After swapping: a =", a, "b =", b)

39. How do you concatenate a string and a number in Python?


Answer: Convert the number to a string using str() and then concatenate. Example: "The number is " +
str(10).

40. Write a Python program to convert a number from Celsius to Fahrenheit.


Answer:
python
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius 9/5) + 32
print("Temperature in Fahrenheit:", fahrenheit)

41. Explain the input() function in Python.


Answer: The input() function reads a line of text from the user and returns it as a string.

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)

43. How do you check if a string is numeric in Python?


Answer: Use the isnumeric() method. Example: "123".isnumeric() returns True.

44. Write a Python program to convert a number from decimal to binary.


Answer:
python
decimal = int(input("Enter a decimal number: "))
binary = bin(decimal)
print("Binary representation:", binary)

45. What is the purpose of the len() function in Python?


Answer: The len() function returns the number of items (length) in an object, such as a string or list.

46. Write a Python program to check if a string contains only alphabets.


Answer:
python
text = input("Enter a string: ")
if text.isalpha():
print("The string contains only alphabets.")
else:
print("The string contains characters other than alphabets.")

47. How can you remove whitespace from the beginning and end of a string?
Answer: Use the strip() method. Example: " text ".strip() returns "text".

48. Write a Python program to find the length of a list.


Answer:
python
my_list = [1, 2, 3, 4, 5]
length = len(my_list)
print("Length of the list:", length)

49. How do you convert a list to a string in Python?


Answer: Use the join() method. Example: " ".join(['a', 'b', 'c']) returns "a b c".

50. Write a Python program to reverse a string.


Answer:
python
text = input("Enter a string: ")
reversed_text = text[::-1]
print("Reversed string:", reversed_text)

Section E: Case Study Based Questions

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")

choice = input("Enter choice (1/2/3/4): ")

num1 = float(input("Enter first number: "))


num2 = float(input("Enter second number: "))

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:

- Arithmetic Operators: Used for basic arithmetic operations. Examples

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.

- Comparison Operators: Used to compare values. Examples include:


- == (Equal to): Checks if two values are equal. Example: 5 == 3 results in False.
- != (Not equal to): Checks if two values are not equal. Example: 5 != 3 results in True.
- > (Greater than): Checks if one value is greater than another. Example: 5 > 3 results in True.
- < (Less than): Checks if one value is less than another. Example: 5 < 3 results in False.
- >= (Greater than or equal to): Checks if one value is greater than or equal to another. Example: 5
>= 3 results in True.
- <= (Less than or equal to): Checks if one value is less than or equal to another. Example: 5 <= 3
results in False.

- Logical Operators: Used to combine conditional statements. Examples include:


- and: Returns True if both conditions are true. Example: (5 > 3) and (2 < 4) results in True.
- or: Returns True if at least one condition is true. Example: (5 > 3) or (2 > 4) results in True.
- not: Returns True if the condition is false. Example: not (5 > 3) results in False.

- Assignment Operators: Used to assign values to variables. Examples include:


- = (Assign): Assigns a value to a variable. Example: x = 5.
- += (Add and assign): Adds a value and assigns the result. Example: x += 3 results in x being 8.
- -= (Subtract and assign): Subtracts a value and assigns the result. Example: x -= 3 results in x being
2.
- = (Multiply and assign): Multiplies a value and assigns the result. Example: x = 3 results in x being
15.
- /= (Divide and assign): Divides a value and assigns the result. Example: x /= 2 results in x being 2.5.

- Bitwise Operators: Used to perform bit-level operations. Examples include:


- & (Bitwise AND): Performs a bitwise AND operation. Example: 5 & 3 results in 1.
- | (Bitwise OR): Performs a bitwise OR operation. Example: 5 | 3 results in 7.
- ^ (Bitwise XOR): Performs a bitwise XOR operation. Example: 5 ^ 3 results in 6.
- ~ (Bitwise NOT): Inverts all the bits of the value. Example: ~5 results in -6.
- << (Left Shift): Shifts bits to the left. Example: 5 << 1 results in 10.
- >> (Right Shift): Shifts bits to the right. Example: 5 >> 1 results in 2.

You might also like