0% found this document useful (0 votes)
3 views

Python-Practices-by-Raihan-Sobhan-sir

The document contains a series of Python programming practice problems and their solutions, covering topics such as salary calculation, loan eligibility, age validation for retirement, profit or loss calculation, tax bracket determination, and more. Each problem includes user input prompts and conditional logic to handle various scenarios and outputs. The solutions are designed for beginners to practice basic programming concepts in Python.

Uploaded by

debojitdutta187
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python-Practices-by-Raihan-Sobhan-sir

The document contains a series of Python programming practice problems and their solutions, covering topics such as salary calculation, loan eligibility, age validation for retirement, profit or loss calculation, tax bracket determination, and more. Each problem includes user input prompts and conditional logic to handle various scenarios and outputs. The solutions are designed for beginners to practice basic programming concepts in Python.

Uploaded by

debojitdutta187
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1

Python: Practice Problems and Solutions (Raihan Sobhan Sir)


1. Salary Calculator: Input hours worked and hourly rate, then calculate and print the total salary.

hours=float(input("How many hours did you work?: "))

rate=float(input("What is your hourly rate of income?: "))

if hours>0 and rate>0:

salary = hours * rate

print(f"You have earned {salary}")

else:

print("Something is wrong with the input, try again.")

2. Loan Eligibility Checker: Take user input for income and expenses, then determine if they

qualify for a loan based on predefined conditions.

#Using the 50/30/20 rule

income=float(input("How much do you earn in a month?: "))

expenses=float(input("On average how much do you spend in a month?: "))

savings=income-expenses

if income>0 and expenses>0 and income>expenses:

if (savings/income)>=.2:

print(f"Since you save 20% or more than that, you are eligible for loan.")

else:

print(f"Since you don’t save that much you are not eligible for the loan.")

else:

print("Something is wrong with the input, try again.")

Made by Pallab Kumar Nakti A&IS (29th)


2

3. Age Validator for Retirement: Input age and check if the person is eligible for retirement (e.g.,

60+ years old).

age=float(input("Enter your age: "))

if 60<age<115:

print(f'Since your age is {round(age, 1)}, you can are eligible for retire.')

elif 0<age<20:

print("Live your life kid!")

elif 60>=age>=20:

print("You are not eligible for the retirement.")

else:

print("Something is wrong with the input, try again.")

4. Profit or Loss Calculator: Take cost price and selling price as input and print if there’s a profit,

loss, or no gain.

cost=float(input("What is the cost of production or procurement?: "))

sell=float(input("What price are you selling the product for?: "))

profit=sell-cost

if cost>0 and sell>0:

if profit>0:

print(f"You've made a profit of {profit}.")

elif profit<0:

print(f"You've made a loss of {abs(profit)}.")

else:

print("You've made no profit or loss")

else:

print("Something is wrong with the input, try again.")

Made by Pallab Kumar Nakti A&IS (29th)


3

5. Tax Bracket Finder: Input income and determine the applicable tax rate based on different

brackets.

# Personal income tax rates

# Resident individual or non-resident individual (NRI) who is a Bangladeshi citizen

for financial year (FY) 2023/24

income=float(input("How much do you earn in a year?: "))

if income>0:

print(f"You earn BDT {income}")

if income<=350000:

print("You don't have to pay any taxes.")

elif income<=450000:

tax=(income - 350000) * .05

print(f"You'll have to pay a tax of BDT {tax}")

elif income<=850000:

tax = ((income - 450000) * .1) + 5000

print(f"You'll have to pay a tax of BDT {tax}")

elif income<=1350000:

tax = ((income - 850000) * .15) + 5000 + 40000

print(f"You'll have to pay a tax of BDT {tax}")

elif income<=1850000:

tax = ((income - 1350000) * .2) + 5000 + 40000 + 75000

print(f"You'll have to pay a tax of BDT {tax}")

elif income>1850000:

tax = ((income - 1850000) * .25) + 5000 + 40000 + 75000 + 100000

print(f"You'll have to pay a tax of BDT {tax}")

else:

print(f"Your income cannot be BDT {income}")

Made by Pallab Kumar Nakti A&IS (29th)


4

6. Odd or Even Number Checker: Input a number and print whether it is odd or even.

num=float(input("Input an integer number you want to check: "))

if num%2==0:

print("The number is even.")

elif num%2==1:

print("The number is odd.")

else:

print("Maybe you input a float.")

7. Sum of First N Numbers: Ask for a number and calculate the sum of all numbers from 1 to that

number.

Easy way

n=int(input("Input a number :) : "))

total=(n*(n+1))/2

print(f'The total all the numbers from 1 to {n} is {int(total)}')

Hard way

n=int(input("Input a number :) : "))

i=1

total = 0

while i<=n:

total+=i

i+=1

print(total)

Made by Pallab Kumar Nakti A&IS (29th)


5

8. Find the Largest Number: Let users enter 5 numbers and print the largest one.

Easy way

n1=float(input("Input the 1st number: "))

n2=float(input("Input the 2nd number: "))

n3=float(input("Input the 3rd number: "))

n4=float(input("Input the 4th number: "))

n5=float(input("Input the 5th number: "))

numlist=[]

numlist.append(n1)

numlist.append(n2)

numlist.append(n3)

numlist.append(n4)

numlist.append(n5)

print(f'The maximum number from the list of \n {numlist} \n is {max(numlist)}')

Hard way

n1=float(input("Input the 1st number: "))

n2=float(input("Input the 2nd number: "))

n3=float(input("Input the 3rd number: "))

n4=float(input("Input the 4th number: "))

n5=float(input("Input the 5th number: "))

numlist=[]

max=n1

numlist.append(n1)

numlist.append(n2)

numlist.append(n3)

numlist.append(n4)

numlist.append(n5)

Made by Pallab Kumar Nakti A&IS (29th)


6

for x in numlist:

if x>= max:

max=x

print(f'The maximum number from the list of \n {numlist} \n is {max}')

9. Grade Calculator: Take marks for 3 subjects, calculate the average, and print the corresponding

letter grade.

numlist=[]

a=float(input("Number in ACC: "))

e=float(input("Number in ECON: "))

m=float(input("Number in MKT: "))

numlist.append(a)

numlist.append(e)

numlist.append(m)

if a>=0 and e>=0 and m>=0:

avg = sum(numlist) / len(numlist)

if avg>=80:

print("You got A+")

elif 70<=avg<80:

print("You got A")

elif 60<=avg<70:

print("You got A-")

elif 50<=avg<60:

print("You got B")

elif 40<=avg<50:

print("You got C")

else: print("You have 'Failed'")

else: print("Something is wrong with the input.")

Made by Pallab Kumar Nakti A&IS (29th)


7

10. Bank Loan Interest Calculator: Depending on the loan type (e.g., home, car, personal), apply

different interest rates and display the total payable amount.

type=input("What type of loan do you have? (Home/Car/Personal): ").upper()

amount=float(input("What is the amount of the loan?: "))

interest=0

if amount>0 and type=="HOME" or type=="CAR" or type=="PERSONAL":

if type == "HOME":

interest = .05

elif type == "CAR":

interest = .07

elif type == "PERSONAL":

interest = .1

type = type.capitalize()

intamount = interest * amount

print(f"On your {type} loan of {amount}, You'll have to pay annual interest

of {intamount}")

else:

print("Wrong Input")

END

Made by Pallab Kumar Nakti A&IS (29th)

You might also like