0% found this document useful (0 votes)
13 views10 pages

Rihen Python Experimment 2

Tinder and python and how they fit
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)
13 views10 pages

Rihen Python Experimment 2

Tinder and python and how they fit
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/ 10

Department of Artificial Intelligence and Machine Learning

Sy.B.Tech. Sem: III Subject: Python Laboratory (DJS23ALPC303) Experiment


2
Name: Rihen Moradia SAP ID: 60017230091
Date: Experiment Title: Decision Making Statements
Aim Write python programs to demonstrate applications of different
decisionmaking statements in python.
Software Google Colab, Visual Studio Code, Jupyter Notebook
Theory To Be 1. What is the purpose of the if statement in Python, and how does it
Handwritten function in a basic decision-making scenario?

2. Explain the difference between the if, elif, and else statements in
Python. Provide an example to illustrate their usage.

3. How does Python handle nested if statements, and what are some
best practices for using nested decision-making statements to ensure
code readability and maintainability?

4. Describe the role of logical operators (and, or, not) in decisionmaking


statements. How do they affect the flow of a program?

5. What are some common pitfalls or errors when using decisionmaking


statements in Python, and how can they be avoided?
SOLUTIONS:
Implementation If Statement: Checks if a number is positive.

If-Else Statement: Determines if a number is even or odd.

If-Elif-Else Statement: Assigns a grade based on marks input.

Nested If-Else Statement: Classifies a triangle based on the lengths of its sides.
Problem Statements

Problem 1: Leap Year Checker


Write a Python program that checks if a given year is a leap year. Ask user
to input the year. A year is a leap year if:
● It is divisible by 4, but not by 100, unless it is also divisible by
400.

OUTPUT:

Problem 2: Vowel or Consonant


Write a Python program that takes a single character as input and checks
whether it is a vowel or a consonant. Assume the input is a single
alphabetic character.
n = input("Enter a character: ") if(n=='a'or n=='e'or
n=='i'or n=='o'or n=='u'or n=='A'or n=='E'or n=='I'or
n=='O'or n=='U'):
print("IT'S A VOWEL") else:
print("IT'S NOT A VOWEL")

OUTPUT:

Problem 3: Electricity Bill Calculation


Write a Python program that calculates the electricity bill based on the
following criteria:
● For the first 100 units, the cost is $0.50 per unit.
● For the next 100 units, the cost is $0.75 per unit.
● For the next 100 units, the cost is $1.20 per unit.
● For units above 300, the cost is $1.50 per unit. Take the number of
units consumed as input and print the total bill amount.
OUTPUT:

Problem 4: BMI Calculator


Write a Python program that calculates the Body Mass Index (BMI) and
categorizes it based on the following criteria:
● BMI < 18.5: Underweight
● 18.5 ≤ BMI < 24.9: Normal weight
● 25 ≤ BMI < 29.9: Overweight
● BMI ≥ 30: Obesity The program should take the weight (in kg)
and height (in meters) as input.
OUTPUT:

Problem 5: Shopping Discount


Write a Python program that calculates the total price after applying a
discount based on the following criteria:
● If the purchase amount is more than $1000, apply a 10%
discount.
● If the purchase amount is between $500 and $1000, apply a 5%
discount.
● If the purchase amount is less than $500, no discount is applied.
Take the purchase amount as input and print the final price after
applying the discount.

OUTPUT:

Problem 6 : ATM Transaction


Write a Python program to simulate an ATM transaction. The program
should:
● Ask the user to enter their balance.
● Provide options to check balance, deposit money, withdraw
money, or exit.
● Update the balance accordingly and display the updated balance
after each transaction.
balance=int(input("ENTER THE BALANCE : "))

option = int(input("ENTER 1 TO CHECK BALANCE , 2 TO


DEPOSIT MONEY , 3 TO WITHDRAW MONEY: "))

if(option==1):
print(f"YOUR BALANCE IS {balance}")
elif(option==2):
amount=int(input("ENTER AMOUNT TO DEPOSIT: "))
newBalance=balance+amount print(f"YOUR
UPDATED BALANCE IS: {newBalance}") elif(option==3):
amount=int(input("ENTER AMOUNT TO WITHDRAW: "))
if(amount<=balance):
newBalance=balance-amount print(f"YOUR
UPDATED BALANCE IS: {newBalance}") else:
print("Insufficent balance ")
else:
print("SOMETHING WENT WRONG!!!")

OUTPUT:

Conclusion Hence, we have studied applications of different decision-making


statements in python.

Signature of Faculty

You might also like