chore: move question & output files

Move python question files to 'questions' directory
Move output files to 'outputs' directory
Copy output files to 'questions' for ease of viewing

Signed-off-by: Neil <neil@willofsteel.me>
This commit is contained in:
Neil Revin 2025-06-24 02:34:07 +05:30
parent 9b10be8414
commit 780baf678e
Signed by: Neil
GPG key ID: 9C54D0F528D78694
54 changed files with 388 additions and 0 deletions

View file

@ -0,0 +1,13 @@
Question 01:
Write a Python program to accept two integers and print their sum.
Answer:
def main(int1: int, int2: int) -> int:
print(f"{int1} + {int2} = {int1 + int2}")
if __name__ == '__main__':
main(2, 2)
Output:
2 + 2 = 4

View file

@ -0,0 +1,14 @@
Question 02:
Write a Python program that accepts the radius of a circle and prints its area.
Answer:
def main(radius: int):
print(f"Area: {3.14 * radius * radius}")
# or you can do 3.13 * radius ** 2
if __name__ == '__main__':
main(7)
Output:
Area: 153.86

View file

@ -0,0 +1,15 @@
Question 03:
Write a Python program to accept the length and width of a rectangle and compute its perimeter and area.
Answer:
def main(length: int, width: int) -> None:
print("Perimeter:", 2 * (length + width))
print("Area:", length * width)
if __name__ == '__main__':
main(10, 10)
Output:
Perimeter: 40
Area: 100

View file

@ -0,0 +1,13 @@
Question 04:
Write a Python program to compute simple interest for a given principal amount, time, and rate of interest.
Answer:
def main(principal: int, time: int, rate: float) -> None:
print(f"Simple Interest: {principal * rate * time / 100}")
if __name__ == '__main__':
main(10000, 10, 5.0)
Output:
Simple Interest: 5000.0

View file

@ -0,0 +1,15 @@
Question 05:
Write a Python program to find whether a given number is even or odd.
Answer:
def main(num: int) -> None:
print("Even" if num % 2 == 0 else "Odd")
if __name__ == '__main__':
main(2)
main(3)
Output:
Even
Odd

View file

@ -0,0 +1,26 @@
Question 06:
Write a Python program to find the largest among three numbers.
Answer:
def main(numbers: list[int]) -> None:
if not numbers:
print("No numbers provided.")
return
largest = numbers[0]
for num in numbers:
if num > largest:
largest = num
print("Largest number:", largest)
if __name__ == '__main__':
main([1, 2, 3])
main([3, 1, 2])
main([5, 10, 15, 20])
Output:
Largest number: 3
Largest number: 3
Largest number: 20

View file

@ -0,0 +1,34 @@
Question 07:
Write a Python program to perform arithmetic calculation. The program should accept two operands and an operator, then display the result.
Answer:
def main(num1: float, num2: float, operator: str) -> None:
if operator == '+':
result = num1 + num2
elif operator == '-':
result = num1 - num2
elif operator == '*':
result = num1 * num2
elif operator == '/':
if num2 == 0:
print("Error: Division by zero")
raise ZeroDivisionError
result = num1 / num2
else:
print("Error: Invalid operator")
raise ValueError("Invalid operator. Use +, -, *, or /.")
print(f"Result: {result}")
if __name__ == '__main__':
main(10, 5, '+')
main(10, 5, '-')
main(10, 5, '*')
main(10, 5, '/')
Output:
Result: 15
Result: 5
Result: 50
Result: 2.0

View file

@ -0,0 +1,18 @@
Question 08:
Write a Python program to check whether a given year is a leap year or not.
Answer:
def main(year: int) -> None:
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(f"{year} is a leap year.")
else:
print(f"{year} is not a leap year.")
if __name__ == '__main__':
main(2020)
main(2021)
Output:
2020 is a leap year.
2021 is not a leap year.

View file

@ -0,0 +1,23 @@
Question 09:
Write a Python program to check if a number is positive, negative, or zero.
Answer:
def main(num: int) -> None:
if num > 0:
print(f"{num} is positive.")
elif num < 0:
print(f"{num} is negative.")
else:
print("The number is zero.")
if __name__ == '__main__':
main(10)
main(-5)
main(0)
Output:
10 is positive.
-5 is negative.
The number is zero.

View file

@ -0,0 +1,38 @@
Question 10:
Write a Python program to accept marks of a student and print the grade according to the given criteria:
Answer:
- Marks ≥ 90: A
- Marks ≥ 80: B
- Marks ≥ 70: C
- Marks ≥ 60: D
- Otherwise: Fail
"""
def main(marks: int) -> None:
if marks >= 90:
grade = 'A'
elif marks >= 80:
grade = 'B'
elif marks >= 70:
grade = 'C'
elif marks >= 60:
grade = 'D'
else:
grade = 'Fail'
print(f"Grade: {grade}")
if __name__ == '__main__':
main(95)
main(85)
main(75)
main(65)
main(55)
Output:
Grade: A
Grade: B
Grade: C
Grade: D
Grade: Fail

View file

@ -0,0 +1,29 @@
Question 11:
Write a Python program to check whether a given character is a vowel or consonant.
Answer:
def main(char: str) -> None:
vowels = 'aeiou'
if char.lower() in vowels:
print(f"{char} is a vowel.")
elif char.isalpha():
print(f"{char} is a consonant.")
else:
raise ValueError("Invalid input. Please enter an alphabetic character.")
if __name__ == '__main__':
main('a')
main('b')
main('A')
main('1') # also works with a int
Output:
Traceback (most recent call last):
File "\\homeassistant.local\share\data\school\Grade 11 CS\Practical File\question_11.py", line 17, in <module>
main('1') # also works with a int
^^^^^^^^^
File "\\homeassistant.local\share\data\school\Grade 11 CS\Practical File\question_11.py", line 10, in main
raise ValueError("Invalid input. Please enter an alphabetic character.")
ValueError: Invalid input. Please enter an alphabetic character.

View file

@ -0,0 +1,22 @@
Question 12:
Write a Python program to check whether a number is divisible by both 5 and 11.
Answer:
def main(num: int) -> None:
if num % 5 == 0 and num % 11 == 0:
print(f"{num} is divisible by both 5 and 11.")
else:
print(f"{num} is not divisible by both 5 and 11.")
if __name__ == '__main__':
main(55)
main(22)
main(10)
main(121)
Output:
55 is divisible by both 5 and 11.
22 is not divisible by both 5 and 11.
10 is not divisible by both 5 and 11.
121 is not divisible by both 5 and 11.

View file

@ -0,0 +1,18 @@
Question 13:
Write a Python program to find the absolute value of a number.
Answer:
def main(num: float) -> None:
abs_value = abs(num)
print(f"The absolute value of {num} is {abs_value}")
if __name__ == '__main__':
main(-5.5)
main(3.14)
main(0)
Output:
The absolute value of -5.5 is 5.5
The absolute value of 3.14 is 3.14
The absolute value of 0 is 0

View file

@ -0,0 +1,27 @@
Question 14:
Write a Python program to check if a character is an uppercase or lowercase letter.
Answer:
def main(char: str) -> None:
if char.isupper():
print(f"{char} is an uppercase letter.")
elif char.islower():
print(f"{char} is a lowercase letter.")
else:
raise ValueError("Invalid input. Please enter an alphabetic character.")
if __name__ == '__main__':
main('A')
main('a')
main('B')
main('b')
main('1') # also works with a int
Output:
Traceback (most recent call last):
File "\\homeassistant.local\share\data\school\Grade 11 CS\Practical File\question_14.py", line 16, in <module>
main('1') # also works with a int
^^^^^^^^^
File "\\homeassistant.local\share\data\school\Grade 11 CS\Practical File\question_14.py", line 9, in main
raise ValueError("Invalid input. Please enter an alphabetic character.")
ValueError: Invalid input. Please enter an alphabetic character.

View file

@ -0,0 +1,20 @@
Question 15:
Write a Python program to accept age and check whether the person is eligible to vote (18 or older).
Answer:
def main(age: int) -> None:
if age >= 18:
print(f"Age {age} is eligible to vote.")
else:
print(f"Age {age} is not eligible to vote.")
if __name__ == '__main__':
main(18)
main(17)
main(20)
Output:
Age 18 is eligible to vote.
Age 17 is not eligible to vote.
Age 20 is eligible to vote.

View file

@ -0,0 +1,25 @@
Question 16:
Write a Python program to accept three sides and check whether they form a valid triangle.
Answer:
def main(sides: tuple[int, int, int]) -> None:
a, b, c = sides
if a + b > c and a + c > b and b + c > a:
print(f"The sides {sides} form a valid triangle.")
else:
print(f"The sides {sides} do not form a valid triangle.")
if __name__ == '__main__':
main((3, 4, 5))
main((1, 2, 3))
main((5, 12, 13))
main((7, 10, 5))
main((1, 1, 2))
Output:
The sides (3, 4, 5) form a valid triangle.
The sides (1, 2, 3) do not form a valid triangle.
The sides (5, 12, 13) form a valid triangle.
The sides (7, 10, 5) form a valid triangle.
The sides (1, 1, 2) do not form a valid triangle.

View file

@ -0,0 +1,21 @@
Question 17:
Write a Python program to accept cost price and selling price, then print whether there is profit, loss, or no gain.
Answer:
def main(cost_price: float, selling_price: float) -> None:
if selling_price > cost_price:
print(f"Profit: {selling_price - cost_price}")
elif selling_price < cost_price:
print(f"Loss: {cost_price - selling_price}")
else:
print("No gain, no loss.")
if __name__ == '__main__':
main(100.0, 120.0)
main(150.0, 130.0)
main(200.0, 200.0)
Output:
Profit: 20.0
Loss: 20.0
No gain, no loss.

View file

@ -0,0 +1,17 @@
Question 18:
Write a Python program to accept two numbers and check whether they are equal or not
Answer:
def main(num1: int, num2: int) -> None:
if num1 == num2:
print(f"{num1} and {num2} are equal.")
else:
print(f"{num1} and {num2} are not equal.")
if __name__ == '__main__':
main(10, 10)
main(10, 20)
Output:
10 and 10 are equal.
10 and 20 are not equal.