Py PDF2
Py PDF2
return round(future_value, 2)
amt = 10000
rate = 3.5
years = 7
# Output:
import math
# Example 1
x1, y1 = 3, 4
x2, y2 = 7, 7
# Example 2
x1, y1 = 3, 4
x2, y2 = 4, 3
# Output:
3. Sum Double
return (a + b) * 2 if a == b else a + b
print(f"sum_double(1,2) → {sum_double(1,2)}")
print(f"sum_double(3,2) → {sum_double(3,2)}")
print(f"sum_double(2,2) → {sum_double(2,2)}")
# Output:
# sum_double(1,2) → 3
# sum_double(3,2) → 5
# sum_double(2,2) → 8
4. Parrot Trouble
# Output:
# parrot_trouble(True, 6) → True
# parrot_trouble(True, 7) → False
# parrot_trouble(False, 6) → False
5. Positive Negative
if negative:
print(f"pos_neg(1,-1,False) → {pos_neg(1,-1,False)}")
print(f"pos_neg(-1,1,False) → {pos_neg(-1,1,False)}")
print(f"pos_neg(-4,-5,True) → {pos_neg(-4,-5,True)}")
# Output:
# pos_neg(1,-1,False) → True
# pos_neg(-1,1,False) → True
# pos_neg(-4,-5,True) → True
6. Near Hundred
def near_hundred(n):
print(f"near_hundred(93) → {near_hundred(93)}")
print(f"near_hundred(90) → {near_hundred(90)}")
print(f"near_hundred(89) → {near_hundred(89)}")
# Output:
# near_hundred(93) → True
# near_hundred(90) → True
# near_hundred(89) → False
7. Difference 21
if n > 21:
print(f"diff21(19) → {diff21(19)}")
print(f"diff21(10) → {diff21(10)}")
print(f"diff21(21) → {diff21(21)}")
# Output:
# diff21(19) → 2
# diff21(10) → 11
# diff21(21) → 0
8. Basic Calculator
def calculator():
print("Basic Calculator")
print("----------------------------------------")
if num2 != 0:
else:
else:
print(calculator())
# Sample Output:
# Basic Calculator
# ----------------------------------------
# Result: 15.0
9. Discount Calculator
def calculate_discount():
print("Discount Calculator")
print("----------------------------------------")
discount_percentage = "10%"
else:
discount_percentage = "5%"
calculate_discount()
# Sample Output:
# Discount Calculator
# ----------------------------------------
#
# Original Amount: $150.0
def calculate_grade():
print("Grade Calculator")
print("----------------------------------------")
grade = 'A'
grade = 'B'
grade = 'C'
grade = 'D'
else:
grade = 'F'
print(f"\nScore: {score}")
print(f"Grade: {grade}")
calculate_grade()
# Sample Output:
# Grade Calculator
# ----------------------------------------
# Score: 85.0
# Grade: B
def is_century_leap_year(year):
print("Century and Leap Year Checker by Rajdeep Mishra, Roll No: 2300971520150")
year = 2000
# Output:
# Century and Leap Year Checker by Rajdeep Mishra, Roll No: 2300971520150
if gender.lower() == 'female':
return 8.2
return 9.2
return 8.4
return 10.5
# Test cases
def get_month_name(month):
months = {
# Test cases
def sum_of_digits(number):
# Test cases
print("* " * i)
# Test case
print_floyd_triangle(3)
def is_palindrome(number):
num_str = str(number)
return lst.count(x)
# Test cases
x1 = 10
lst2 = [8, 6, 8, 10, 8, 20, 10, 8, 8]
x2 = 16
def find_second_largest(lst):
if len(lst) < 2:
return None
# Test case
# Test case
elements_to_remove = [3, 5, 7]
def find_duplicates(lst):
seen = set()
duplicates = set()
if num in seen:
duplicates.add(num)
seen.add(num)
return list(duplicates)
# Test cases
list1 = [10, 20, 30, 20, 20, 30, 40, 50, -20, 60, 60, -20, -20]
print(f"Input: {list1}")
print(f"Output: {find_duplicates(list1)}")
return [item for item in list1 + list2 if (item in list1) ^ (item in list2)]
# Test case
print(f"List 1: {list1}")
print(f"List 2: {list2}")
freq_dict = {}
if num in freq_dict:
freq_dict[num] += 1
else:
freq_dict[num] = 1
# Test cases
test_list1 = [4, 6, 4, 3, 3, 4, 3, 4, 3, 8]
K1 = 3
test_list2 = [4, 6, 4, 3, 3, 4, 3, 4, 6, 6]
K2 = 2
def check_consecutive(lst):
return lst[i]
return None
# Test cases
list1 = [4, 5, 5, 5, 3, 8]
print(f"Output: {check_consecutive(list1)}")
print(f"Output: {check_consecutive(list2)}")
def find_strongest_neighbour(lst):
# Test cases
arr1 = [1, 2, 2, 3, 4, 5 ]
arr2 = [5, 5]
print(f"Output: {find_strongest_neighbour(arr1)}")
print(f"\nInput Array 2: {arr2}")
print(f"Output: {find_strongest_neighbour(arr2)}")
import itertools
def print_combinations(digits):
for p in itertools.permutations(digits):
# Test cases
digits1 = [1, 2, 3]
digits2 = [0, 9, 5]
print_combinations(digits1)
print_combinations(digits2)
# Test cases
K1 = 5
N1 = 2
K2 = 5
N2 = 3