PATTERN & PYRAMID PROGRAMS
ATM & cash withdrawal
balance = 15000
withdraw = int(input("Enter withdrawal amount: "))
if withdraw % 100 != 0:
print("Error: Amount must be multiple of 100")
elif withdraw > 10000:
print("Error: Daily limit exceeded")
elif withdraw > balance - 500:
print("Error: Insufficient balance")
else:
balance -= withdraw
print("Withdrawal successful. Remaining balance:", balance)
Billing
customer = input("Enter customer type (regular/premium): ").lower()
amount = int(input("Enter bill amount: "))
if customer == "regular":
discount = amount * 0.10
elif customer == "premium":
discount = amount * 0.20
else:
discount = 0
print("Final Amount:", amount - discount)
print("Discount Applied:", discount)
BMI
age = int(input("Enter age: "))
bmi = float(input("Enter BMI: "))
if age < 5 or age > 65:
print("Special attention needed")
elif bmi < 18.5:
print("Underweight")
elif bmi < 25:
print("Normal")
elif bmi < 30:
print("Overweight")
else:
print("Obese")
EMPLOYEE PERFORMANCE
salary = float(input("Enter salary: "))
performance = input("Enter performance (excellent/good/average/poor): ").lower()
late_days = int(input("Enter late days: "))
if performance == "excellent":
bonus = 0.2 * salary
elif performance == "good":
bonus = 0.1 * salary
elif performance == "average":
bonus = 0.05 * salary
else:
bonus = 0
if late_days > 5:
bonus /= 2
print("Bonus Amount:", bonus)
GRADING SYSTEM
marks = int(input("Enter marks: "))
attendance = int(input("Enter attendance %: "))
if attendance < 75:
grade = "Fail due to low attendance"
elif marks >= 90:
grade = "A"
elif marks >= 75:
grade = "B"
elif marks >= 60:
grade = "C"
else:
grade = "Fail"
print("Result:", grade)
MEMBERSHIP PROGRAM
plan = input("Enter plan (monthly/quarterly/yearly): ").lower()
if plan == "monthly":
print("Monthly Plan Selected")
elif plan == "quarterly":
print("Quarterly Plan Selected")
elif plan == "yearly":
print("Yearly Plan Selected")
else:
print("Invalid Plan")
print("No Plan Selected")
ELIGIBILITY PROGRAM
salary = int(input("Enter salary: "))
previous_loan = input("Any previous loan? (yes/no): ").lower()
age = int(input("Enter age: "))
if salary <= 20000 or previous_loan == "yes" or age < 21 or age > 60:
print("Loan Not Approved")
else:
print("Loan Approved")
Right triangle
rows = int(input("Enter number of rows: "))
i=1
while i <= rows:
j=1
while j <= i:
print("*", end="10")
j += 1
print()
i += 1
Inverted Right-Angled Triangle
rows = int(input("Enter number of rows: "))
i = rows
while i >= 1:
j=1
while j <= i:
print("*", end=" ")
j += 1
print()
i -= 1
Right-Angled Number Triangle
rows = int(input("Enter number of rows: "))
i=1
while i <= rows:
j=1
while j <= i:
print(j, end=" ")
j += 1
print()
i += 1
Inverted Number Triangle
rows = int(input("Enter number of rows: "))
i = rows
while i >= 1:
j=1
while j <= i:
print(j, end=" ")
j += 1
print()
i -= 1
Pyramid Pattern
rows = int(input("Enter number of rows: "))
i=1
while i <= rows:
space = rows - i
while space > 0:
print(" ", end="")
space -= 1
j=1
while j <= i:
print("*", end=" ")
j += 1
print()
i += 1
Inverted Pyramid
rows = int(input("Enter number of rows: "))
i = rows
while i >= 1:
space = rows - i
while space > 0:
print(" ", end="")
space -= 1
j=1
while j <= i:
print("*", end=" ")
j += 1
print()
i -= 1
Diamond Pattern
rows = int(input("Enter number of rows: "))
i=1
while i <= rows:
space = rows - i
while space > 0:
print(" ", end="")
space -= 1
j=1
while j <= i:
print("*", end=" ")
j += 1
print()
i += 1
Hollow Square Pattern
size = int(input("Enter size: "))
i=1
while i <= size:
j=1
while j <= size:
if i == 1 or i == size or j == 1 or j == size:
print("*", end=" ")
else:
print(" ", end=" ")
j += 1
print()
i += 1
Hollow Triangle
rows = int(input("Enter rows: "))
i=1
while i <= rows:
j=1
while j <= i:
if j == 1 or j == i or i == rows:
print("*", end=" ")
else:
print(" ", end=" ")
j += 1
print()
i += 1
Number Pyramid
rows = int(input("Enter rows: "))
i=1
while i <= rows:
space = rows - i
while space > 0:
print(" ", end="")
space -= 1
j=1
while j <= i:
print(j, end=" ")
j += 1
print()
i += 1
check if a number is prime without range() or any built-in functions
num = int(input("Enter number: "))
if num < 2:
print("Not prime")
else:
i=2
is_prime = True
while i * i <= num:
if num % i == 0:
is_prime = False
break
i += 1
if is_prime:
print("Prime")
else:
print("Not prime")
fibonacci series up to N terms (without using list or range)
terms = int(input("Enter number of terms: "))
a, b = 0, 1
count = 0
while count < terms:
print(a, end=' ')
a, b = b, a + b
count += 1
print()
Sum of first N numbers (without sum() or range())
n = int(input("Enter N: "))
total = 0
i=1
while i <= n:
total += i
i += 1
print("Sum =", total)
factorial of a number without using [Link]
num = int(input("Enter number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial =", factorial)
Reverse a number (without converting to string)
num = int(input("Enter number: "))
rev = 0
while num > 0:
rev = rev * 10 + num % 10
num = num // 10
print("Reversed Number:", rev)