SaitechAI • Worksheet
Python Programming Worksheet — 10 Short Questions
Write your script in the box for each question. Tick “Correct” after verification. Use Show Key to reveal solutions. Weighted total: 20 marks.
Q1. Print the first 10 natural numbers using a loop.
Print numbers 1 to 10 on one line separated by spaces.
Key:
for i in range(1,11):
print(i, end=" ")Q2. Function to check if a number is even or odd.
Key:
def is_even(n: int) -> bool:
return n % 2 == 0Q3. Largest number in a list (no
max()).Key:
nums = [12, 4, 29, 7, -1]
m = nums[0]
for x in nums[1:]:
if x > m:
m = x
print(m)Q4. Factorial using recursion with base cases 0 and 1.
Key:
def fact(n: int) -> int:
return 1 if n <= 1 else n * fact(n-1)Q5. Reverse a string input by the user.
Key:
s = input().strip()
print(s[::-1])Q6. Multiplication table of a number up to 10.
Key:
n = int(input())
for i in range(1, 11):
print(f"{n} x {i} = {n*i}")Q7. Palindrome check ignoring case and spaces.
Key:
t = ''.join(ch.lower() for ch in input() if not ch.isspace())
print("Palindrome" if t == t[::-1] else "Not palindrome")Q8. Count vowels (a, e, i, o, u) in a string.
Key:
s = input().lower()
print(sum(ch in "aeiou" for ch in s))Q9. Swap two variables without using a third variable.
Key:
a, b = 5, 9
a, b = b, a
print(a, b)Q10. Sum of all elements in a list read from a line of input.
Key:
nums = list(map(int, input().split()))
total = 0
for x in nums:
total += x
print(total)Total Score: 0 / 20