1.
ATM SIMULATION WITH WITHDRAWAL LIMITS AND CONDITIONS:
atm_balance = 50000
transaction_limit = 3
def withdraw(user_balance, amount):
global transaction_limit, atm_balance
if transaction_limit == 0:
return "Limit reached."
if amount > user_balance:
return "Insufficient balance."
if amount % 100 != 0:
return "Amount must be a multiple of 100."
if amount > atm_balance:
return "ATM does not have enough cash."
user_balance -= amount
atm_balance -= amount
transaction_limit -= 1
return f"Withdrawn: {amount}. Remaining balance: {user_balance}"
# Example usage
balance = 2000
print(withdraw(balance, 500))
print(withdraw(balance, 700))
print(withdraw(balance, 1000))
print(withdraw(balance, 500))
2. SEQUENCE REMOVAL:
def remove_chars(string, indices):
return ''.join(char for i, char in enumerate(string) if i not in indices)
# Example usage
result = remove_chars("Hello, World!", [0, 2, 4, 7])
print("Result:", result)
3. WORD CHECKER:
def check_word(word):
if len(word) < 3: return "Invalid"
second_char = word[1]
return "Vowel" if second_char.lower() in 'aeiou' else "Digit" if second_char.isdigit() else
"Consonant" if second_char.isalpha() else "Others"
# Example usage
print("Result:", check_word(input("Enter a word: ")))
4. NUMBER CHECKER:
def check_number(number):
num_str = str(number)
if len(num_str) == 1: return f"Square: {number ** 2}"
second_digit = int(num_str[1])
return "24" if second_digit % 4 == 0 else "2" if number % 2 == 0 else "1"
# Example usage
print("Result:", check_number(int(input("Enter a number: "))))
5. DUPLICATE CHECKER:
def find_duplicate(array):
num_set = set()
for num in array:
if num in num_set:
return num
num_set.add(num)
return -1
# Example usage
N = int(input("Enter the number of elements in the array: "))
A = list(map(int, input("Enter the elements of the array: ").split()))
print("Duplicate number:", find_duplicate(A))
6. INTERSECTION:
def find_intersection(array_A, array_B):
# Compute the intersection by converting both lists to sets
intersection = set(array_A).intersection(array_B)
return sorted(intersection)
# Example usage
A = list(map(int, input("Enter the elements of the first array (space-separated): ").split()))
B = list(map(int, input("Enter the elements of the second array (space-separated): ").split()))
print("Intersection:", find_intersection(A, B))
7. FIRST NON REPEATING CHARACTER:
def find_first_non_repeating(string):
char_count = {char: string.count(char) for char in string}
return next((i for i, char in enumerate(string) if char_count[char] == 1), -1)
# Example usage
print("Index:", find_first_non_repeating(input("Enter a string: ")))
8. REVERSE VOWELS:
def reverse_vowels(string):
vowels = [char for char in string if char in 'aeiouAEIOU'][::-1]
return ''.join(char if char not in 'aeiouAEIOU' else vowels.pop(0) for char in string)
# Example usage
print("String after reversing vowels:", reverse_vowels(input("Enter a string: ")))
9. TWIN PRIME:
def count_twin_primes(arr):
primes = sorted(x for x in arr if x > 1 and all(x % i for i in range(2, int(x**0.5) + 1)))
return sum(b - a == 2 for a, b in zip(primes, primes[1:]))
# Example usage
A = list(map(int, input("Enter the elements of the array: ").split()))
print("Twin primes:", count_twin_primes(A))
10. ELECTRICITY BILL:
class ElectricityBill:
def __init__(self, units):
self.units = units
def calculate_bill(self):
if self.units < 0:
return "Invalid units."
rates = [(25, 1.25), (25, 1.45), (25, 1.65), (20, 1.95), (float('inf'), 2.00)]
bill_amount = 0
units_remaining = self.units
for units, rate in rates:
if units_remaining <= 0:
break
consumed_units = min(units, units_remaining)
bill_amount += consumed_units * rate
units_remaining -= consumed_units
return round(bill_amount, 2)
# Example usage
try:
print("Bill: $", ElectricityBill(int(input("Enter metered units: "))).calculate_bill())
except ValueError:
print("Invalid input.")
11.PURCHASE
class Purchase:
def __init__(self, N, P):
self.N, self.P = N, P
def calculate_final_amount(self):
# Calculate discounted items based on quantity
discount_items = 0
if self.N >= 50:
discount_items = 10 if self.N <= 100 else 20 if self.N <= 200 else 30
# Calculate total amount before discount
total_amount = (self.N - discount_items) * self.P
# Determine discount percentage based on total amount
discount = 0.20 if total_amount > 10000 else 0.15 if total_amount > 1000 else 0.10
# Apply discount
final_amount = total_amount * (1 - discount)
return round(final_amount, 2)
# Example usage
N = int(input("Enter the number of items: "))
P = float(input("Enter the price per item: "))
print("Total amount payable: $", Purchase(N, P).calculate_final_amount())
12. PASSWORD GENERATOR
class PasswordGenerator:
def _init_(self, name):
self.name = name
def generate_password(self):
lc, le, fc = self.name[-1], len(self.name), self.name[0]
return f"{lc}{le}{'@' if le % 2 == 0 else '!'}{fc}{'654' if le % 2 == 0 else '432'}{lc}"
# Example usage
name_input = input("Enter the name of a person: ")
print("Generated Password:", PasswordGenerator(name_input).generate_password())