feat: add practical file projects

Signed-off-by: Neil <neil@willofsteel.me>
This commit is contained in:
Neil Revin 2025-06-24 02:28:22 +05:30
commit cc8b0efe94
Signed by: Neil
GPG key ID: 9C54D0F528D78694
39 changed files with 1254 additions and 0 deletions

41
LICENSE Normal file
View file

@ -0,0 +1,41 @@
<!--
Will of Steel Proprietary License (WOSPL)
Copyright (c) 2025-present Will of Steel
This software and its accompanying source code ("the Software") are proprietary and confidential. Unauthorized actions are strictly prohibited. Specifically, you are not permitted to:
- Use the Software for any purpose other than internal review, unless explicitly authorized in writing by the Licensor.
- Modify, adapt, translate, or create derivative works based on the Software.
- Distribute, disclose, sublicense, lease, rent, or otherwise make available the Software to any third party.
- Reverse engineer, decompile, disassemble, or attempt to derive the source code, object code, or underlying structure, ideas, or algorithms of the Software.
- Remove, alter, or obscure any proprietary notices, labels, or marks on the Software.
- Use the Software for any commercial purposes or in any commercial environment.
- Claim ownership or authorship of the Software or any part thereof.
- Use the Software in any manner that violates applicable laws or regulations.
The Software is provided "as is" without warranty of any kind, express or implied. The Licensor shall not be liable for any damages arising out of or in connection with the use or performance of the Software.
Any violation of these terms will result in immediate termination of your rights to use the Software and may subject you to legal action.
For permissions beyond the scope of this license, please contact neil@willofsteel.me-->
Will of Steel Proprietray License (WOSPL)
Copyright (c) 2025-present Will of Steel
This software and its accompanying source code ("the Software") are proprietary and confidential. Unauthorized actions are strictly prohibited. Specifically, you are not permitted to:
- **Use** the Software for any purpose other than internal review, unless explicitly authorized in writing by the Licensor.
- **Modify, adapt, translate, or create derivative works** based on the Software.
- **Distribute, disclose, sublicense, lease, rent, or otherwise make available** the Software to any third party.
- **Reverse engineer, decompile, disassemble, or attempt to derive** the source code, object code, or underlying structure, ideas, or algorithms of the Software.
- **Remove, alter, or obscure** any proprietary notices, labels, or marks on the Software.
- **Use** the Software for any commercial purposes or in any commercial environment.
- **Claim ownership or authorship** of the Software or any part thereof.
- **Use** the Software in any manner that violates applicable laws or regulations.
The Software is provided "as is" without warranty of any kind, express or implied. The Licensor shall not be liable for any damages arising out of or in connection with the use or performance of the Software.
Any violation of these terms will result in immediate termination of your rights to use the Software and may subject you to legal action.
For permissions beyond the scope of this license, please contact neil@willofsteel.me

404
Practical File/outputs.txt Normal file
View file

@ -0,0 +1,404 @@
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
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
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
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
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
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
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
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.
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.
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
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 "\\nas.local\share\data\school\Grade 11 CS\Practical File\question_11.py", line 17, in <module>
main('1') # also works with a int
^^^^^^^^^
File "\\nas.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.
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.
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
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 "\\nas.local\share\data\school\Grade 11 CS\Practical File\question_14.py", line 16, in <module>
main('1') # also works with a int
^^^^^^^^^
File "\\nas.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.
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.
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.
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.
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.

177
Practical File/project.py Normal file
View file

@ -0,0 +1,177 @@
#!/usr/bin/env python3
import os
import subprocess
import sys
def find_next_question_number():
current_dir = os.getcwd()
existing_files = [f for f in os.listdir(current_dir) if f.startswith('question_') and f.endswith('.py')]
if not existing_files:
return 1
numbers = []
for filename in existing_files:
try:
num_str = filename.replace('question_', '').replace('.py', '')
numbers.append(int(num_str))
except ValueError:
continue
return max(numbers) + 1 if numbers else 1
def create_question_file(question_text, question_num):
filename = f"question_{question_num:02d}.py"
with open(filename, 'w') as f:
f.write(f"# Question: {question_text}\n\n")
f.write("")
f.write("def main():\n")
f.write(" pass\n\n")
f.write("")
f.write("if __name__ == '__main__':\n")
f.write(" main()\n")
return filename
def open_in_vscode(filename):
try:
vscode_commands = ['code', 'code-insiders', 'codium']
for cmd in vscode_commands:
try:
subprocess.run([cmd, filename], check=True)
return True
except (subprocess.CalledProcessError, FileNotFoundError):
continue
return False
except Exception as e:
return False
def wait_for_completion():
input("Press Enter when the question is done: ")
return True
def execute_code_and_capture_output(filename):
try:
result = subprocess.run([sys.executable, filename],
capture_output=True,
text=True,
timeout=30)
output = {
'stdout': result.stdout,
'stderr': result.stderr,
'returncode': result.returncode
}
return output
except subprocess.TimeoutExpired:
return {
'stdout': '',
'stderr': 'Code execution timed out',
'returncode': 1
}
except Exception as e:
return {
'stdout': '',
'stderr': f'Error executing code: {str(e)}',
'returncode': 1
}
def read_code_from_file(filename):
try:
with open(filename, 'r') as f:
lines = f.readlines()
if len(lines) >= 2:
return ''.join(lines[2:])
else:
return ''.join(lines)
except Exception as e:
return f"Error reading file: {str(e)}"
def append_to_master_file(question_text, question_num, code_content, execution_output):
with open("outputs.txt", "a") as f:
if os.path.getsize("outputs.txt") == 0:
pass
else:
f.write("\n\n")
f.write(f"Question {question_num:02d}: {question_text}\n\n")
f.write("Answer:\n")
f.write(code_content)
f.write("\n\nOutput:\n")
if execution_output['returncode'] == 0:
if execution_output['stdout']:
f.write(execution_output['stdout'])
else:
f.write("No output")
else:
if execution_output['stderr']:
f.write(execution_output['stderr'])
else:
f.write("Error occurred")
def create_output_file(question_text, question_num, filename, code_content, execution_output):
output_filename = f"question_{question_num:02d}_output.txt"
with open(output_filename, 'w') as f:
f.write(f"Question {question_num:02d}:\n")
f.write(f"{question_text}\n\n")
f.write("Answer:\n")
f.write(code_content)
f.write("\n\nOutput:\n")
if execution_output['returncode'] == 0:
if execution_output['stdout']:
f.write(execution_output['stdout'])
else:
f.write("No output")
else:
if execution_output['stderr']:
f.write(execution_output['stderr'])
else:
f.write("Error occurred")
return output_filename
def main():
question = input("Enter your question: ").strip()
if not question:
return
question_num = find_next_question_number()
filename = create_question_file(question, question_num)
open_in_vscode(filename)
wait_for_completion()
code_content = read_code_from_file(filename)
execution_output = execute_code_and_capture_output(filename)
create_output_file(question, question_num, filename, code_content, execution_output)
append_to_master_file(question, question_num, code_content, execution_output)
if execution_output['returncode'] == 0:
if execution_output['stdout']:
print("Output:")
print(execution_output['stdout'])
else:
print("No output")
else:
print("Error:")
if execution_output['stderr']:
print(execution_output['stderr'])
else:
print("Error occurred")
if __name__ == "__main__":
while True:
main()
print("------------------------------------------------\n\n\n\n\n\n")

View file

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

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,8 @@
# Question: Write a Python program that accepts the radius of a circle and prints its area.
def main(radius: int):
print(f"Area: {3.14 * radius * radius}")
# or you can do 3.13 * radius ** 2
if __name__ == '__main__':
main(7)

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,8 @@
# Question: Write a Python program to accept the length and width of a rectangle and compute its perimeter and area.
def main(length: int, width: int) -> None:
print("Perimeter:", 2 * (length + width))
print("Area:", length * width)
if __name__ == '__main__':
main(10, 10)

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,7 @@
# Question: Write a Python program to compute simple interest for a given principal amount, time, and rate of interest.
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)

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,8 @@
# Question: Write a Python program to find whether a given number is even or odd.
def main(num: int) -> None:
print("Even" if num % 2 == 0 else "Odd")
if __name__ == '__main__':
main(2)
main(3)

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,18 @@
# Question: Write a Python program to find the largest among three numbers.
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])

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,25 @@
# Question: Write a Python program to perform arithmetic calculation. The program should accept two operands and an operator, then display the result.
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, '/')

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,11 @@
# Question: Write a Python program to check whether a given year is a leap year or not.
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)

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,15 @@
# Question: Write a Python program to check if a number is positive, negative, or zero.
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)

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,29 @@
"""
Question: Write a Python program to accept marks of a student and print the grade according to the given criteria:
- 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)

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,17 @@
# Question: Write a Python program to check whether a given character is a vowel or consonant.
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

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,13 @@
# Question: Write a Python program to check whether a number is divisible by both 5 and 11.
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)

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,10 @@
# Question: Write a Python program to find the absolute value of a number.
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)

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,16 @@
# Question: Write a Python program to check if a character is an uppercase or lowercase letter.
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

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,12 @@
# Question: Write a Python program to accept age and check whether the person is eligible to vote (18 or older).
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)

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,15 @@
# Question: Write a Python program to accept three sides and check whether they form a valid triangle.
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))

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,14 @@
# Question: Write a Python program to accept cost price and selling price, then print whether there is profit, loss, or no gain.
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)

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,11 @@
# Question: Write a Python program to accept two numbers and check whether they are equal or not
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)

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.