diff --git a/Practical File/question_01_output.txt b/Practical File/outputs/question_01_output.txt similarity index 100% rename from Practical File/question_01_output.txt rename to Practical File/outputs/question_01_output.txt diff --git a/Practical File/question_02_output.txt b/Practical File/outputs/question_02_output.txt similarity index 100% rename from Practical File/question_02_output.txt rename to Practical File/outputs/question_02_output.txt diff --git a/Practical File/question_03_output.txt b/Practical File/outputs/question_03_output.txt similarity index 100% rename from Practical File/question_03_output.txt rename to Practical File/outputs/question_03_output.txt diff --git a/Practical File/question_04_output.txt b/Practical File/outputs/question_04_output.txt similarity index 100% rename from Practical File/question_04_output.txt rename to Practical File/outputs/question_04_output.txt diff --git a/Practical File/question_05_output.txt b/Practical File/outputs/question_05_output.txt similarity index 100% rename from Practical File/question_05_output.txt rename to Practical File/outputs/question_05_output.txt diff --git a/Practical File/question_06_output.txt b/Practical File/outputs/question_06_output.txt similarity index 100% rename from Practical File/question_06_output.txt rename to Practical File/outputs/question_06_output.txt diff --git a/Practical File/question_07_output.txt b/Practical File/outputs/question_07_output.txt similarity index 100% rename from Practical File/question_07_output.txt rename to Practical File/outputs/question_07_output.txt diff --git a/Practical File/question_08_output.txt b/Practical File/outputs/question_08_output.txt similarity index 100% rename from Practical File/question_08_output.txt rename to Practical File/outputs/question_08_output.txt diff --git a/Practical File/question_09_output.txt b/Practical File/outputs/question_09_output.txt similarity index 100% rename from Practical File/question_09_output.txt rename to Practical File/outputs/question_09_output.txt diff --git a/Practical File/question_10_output.txt b/Practical File/outputs/question_10_output.txt similarity index 100% rename from Practical File/question_10_output.txt rename to Practical File/outputs/question_10_output.txt diff --git a/Practical File/question_11_output.txt b/Practical File/outputs/question_11_output.txt similarity index 100% rename from Practical File/question_11_output.txt rename to Practical File/outputs/question_11_output.txt diff --git a/Practical File/question_12_output.txt b/Practical File/outputs/question_12_output.txt similarity index 100% rename from Practical File/question_12_output.txt rename to Practical File/outputs/question_12_output.txt diff --git a/Practical File/question_13_output.txt b/Practical File/outputs/question_13_output.txt similarity index 100% rename from Practical File/question_13_output.txt rename to Practical File/outputs/question_13_output.txt diff --git a/Practical File/question_14_output.txt b/Practical File/outputs/question_14_output.txt similarity index 100% rename from Practical File/question_14_output.txt rename to Practical File/outputs/question_14_output.txt diff --git a/Practical File/question_15_output.txt b/Practical File/outputs/question_15_output.txt similarity index 100% rename from Practical File/question_15_output.txt rename to Practical File/outputs/question_15_output.txt diff --git a/Practical File/question_16_output.txt b/Practical File/outputs/question_16_output.txt similarity index 100% rename from Practical File/question_16_output.txt rename to Practical File/outputs/question_16_output.txt diff --git a/Practical File/question_17_output.txt b/Practical File/outputs/question_17_output.txt similarity index 100% rename from Practical File/question_17_output.txt rename to Practical File/outputs/question_17_output.txt diff --git a/Practical File/question_18_output.txt b/Practical File/outputs/question_18_output.txt similarity index 100% rename from Practical File/question_18_output.txt rename to Practical File/outputs/question_18_output.txt diff --git a/Practical File/question_01.py b/Practical File/questions/question_01.py similarity index 100% rename from Practical File/question_01.py rename to Practical File/questions/question_01.py diff --git a/Practical File/questions/question_01_output.txt b/Practical File/questions/question_01_output.txt new file mode 100644 index 0000000..65cb1d5 --- /dev/null +++ b/Practical File/questions/question_01_output.txt @@ -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 diff --git a/Practical File/question_02.py b/Practical File/questions/question_02.py similarity index 100% rename from Practical File/question_02.py rename to Practical File/questions/question_02.py diff --git a/Practical File/questions/question_02_output.txt b/Practical File/questions/question_02_output.txt new file mode 100644 index 0000000..34ae01f --- /dev/null +++ b/Practical File/questions/question_02_output.txt @@ -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 diff --git a/Practical File/question_03.py b/Practical File/questions/question_03.py similarity index 100% rename from Practical File/question_03.py rename to Practical File/questions/question_03.py diff --git a/Practical File/questions/question_03_output.txt b/Practical File/questions/question_03_output.txt new file mode 100644 index 0000000..391aec0 --- /dev/null +++ b/Practical File/questions/question_03_output.txt @@ -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 diff --git a/Practical File/question_04.py b/Practical File/questions/question_04.py similarity index 100% rename from Practical File/question_04.py rename to Practical File/questions/question_04.py diff --git a/Practical File/questions/question_04_output.txt b/Practical File/questions/question_04_output.txt new file mode 100644 index 0000000..21fea65 --- /dev/null +++ b/Practical File/questions/question_04_output.txt @@ -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 diff --git a/Practical File/question_05.py b/Practical File/questions/question_05.py similarity index 100% rename from Practical File/question_05.py rename to Practical File/questions/question_05.py diff --git a/Practical File/questions/question_05_output.txt b/Practical File/questions/question_05_output.txt new file mode 100644 index 0000000..a8e0387 --- /dev/null +++ b/Practical File/questions/question_05_output.txt @@ -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 diff --git a/Practical File/question_06.py b/Practical File/questions/question_06.py similarity index 100% rename from Practical File/question_06.py rename to Practical File/questions/question_06.py diff --git a/Practical File/questions/question_06_output.txt b/Practical File/questions/question_06_output.txt new file mode 100644 index 0000000..7d172a1 --- /dev/null +++ b/Practical File/questions/question_06_output.txt @@ -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 diff --git a/Practical File/question_07.py b/Practical File/questions/question_07.py similarity index 100% rename from Practical File/question_07.py rename to Practical File/questions/question_07.py diff --git a/Practical File/questions/question_07_output.txt b/Practical File/questions/question_07_output.txt new file mode 100644 index 0000000..c55a0ec --- /dev/null +++ b/Practical File/questions/question_07_output.txt @@ -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 diff --git a/Practical File/question_08.py b/Practical File/questions/question_08.py similarity index 100% rename from Practical File/question_08.py rename to Practical File/questions/question_08.py diff --git a/Practical File/questions/question_08_output.txt b/Practical File/questions/question_08_output.txt new file mode 100644 index 0000000..a61dea2 --- /dev/null +++ b/Practical File/questions/question_08_output.txt @@ -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. diff --git a/Practical File/question_09.py b/Practical File/questions/question_09.py similarity index 100% rename from Practical File/question_09.py rename to Practical File/questions/question_09.py diff --git a/Practical File/questions/question_09_output.txt b/Practical File/questions/question_09_output.txt new file mode 100644 index 0000000..d973aff --- /dev/null +++ b/Practical File/questions/question_09_output.txt @@ -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. diff --git a/Practical File/question_10.py b/Practical File/questions/question_10.py similarity index 100% rename from Practical File/question_10.py rename to Practical File/questions/question_10.py diff --git a/Practical File/questions/question_10_output.txt b/Practical File/questions/question_10_output.txt new file mode 100644 index 0000000..d3270af --- /dev/null +++ b/Practical File/questions/question_10_output.txt @@ -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 diff --git a/Practical File/question_11.py b/Practical File/questions/question_11.py similarity index 100% rename from Practical File/question_11.py rename to Practical File/questions/question_11.py diff --git a/Practical File/questions/question_11_output.txt b/Practical File/questions/question_11_output.txt new file mode 100644 index 0000000..b4d80a4 --- /dev/null +++ b/Practical File/questions/question_11_output.txt @@ -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 + 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. diff --git a/Practical File/question_12.py b/Practical File/questions/question_12.py similarity index 100% rename from Practical File/question_12.py rename to Practical File/questions/question_12.py diff --git a/Practical File/questions/question_12_output.txt b/Practical File/questions/question_12_output.txt new file mode 100644 index 0000000..b401f48 --- /dev/null +++ b/Practical File/questions/question_12_output.txt @@ -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. diff --git a/Practical File/question_13.py b/Practical File/questions/question_13.py similarity index 100% rename from Practical File/question_13.py rename to Practical File/questions/question_13.py diff --git a/Practical File/questions/question_13_output.txt b/Practical File/questions/question_13_output.txt new file mode 100644 index 0000000..4da879f --- /dev/null +++ b/Practical File/questions/question_13_output.txt @@ -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 diff --git a/Practical File/question_14.py b/Practical File/questions/question_14.py similarity index 100% rename from Practical File/question_14.py rename to Practical File/questions/question_14.py diff --git a/Practical File/questions/question_14_output.txt b/Practical File/questions/question_14_output.txt new file mode 100644 index 0000000..ab94cd5 --- /dev/null +++ b/Practical File/questions/question_14_output.txt @@ -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 + 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. diff --git a/Practical File/question_15.py b/Practical File/questions/question_15.py similarity index 100% rename from Practical File/question_15.py rename to Practical File/questions/question_15.py diff --git a/Practical File/questions/question_15_output.txt b/Practical File/questions/question_15_output.txt new file mode 100644 index 0000000..01a2ef9 --- /dev/null +++ b/Practical File/questions/question_15_output.txt @@ -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. diff --git a/Practical File/question_16.py b/Practical File/questions/question_16.py similarity index 100% rename from Practical File/question_16.py rename to Practical File/questions/question_16.py diff --git a/Practical File/questions/question_16_output.txt b/Practical File/questions/question_16_output.txt new file mode 100644 index 0000000..c70c567 --- /dev/null +++ b/Practical File/questions/question_16_output.txt @@ -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. diff --git a/Practical File/question_17.py b/Practical File/questions/question_17.py similarity index 100% rename from Practical File/question_17.py rename to Practical File/questions/question_17.py diff --git a/Practical File/questions/question_17_output.txt b/Practical File/questions/question_17_output.txt new file mode 100644 index 0000000..63d23df --- /dev/null +++ b/Practical File/questions/question_17_output.txt @@ -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. diff --git a/Practical File/question_18.py b/Practical File/questions/question_18.py similarity index 100% rename from Practical File/question_18.py rename to Practical File/questions/question_18.py diff --git a/Practical File/questions/question_18_output.txt b/Practical File/questions/question_18_output.txt new file mode 100644 index 0000000..3701b30 --- /dev/null +++ b/Practical File/questions/question_18_output.txt @@ -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.