0% found this document useful (0 votes)
21 views11 pages

Task 4 - Nested IF

Uploaded by

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

Task 4 - Nested IF

Uploaded by

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

Python 3.11.9 (tags/v3.11.9:de54cf5, Apr 2 2024, 10:12:12) [MSC v.

1938 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> mark = int(input("Enter your mark:"))
Enter your mark: 92
>>>
>>> if mark >= 80 and mark <=100:
... print("Distinction")
... elif mark >= 60 and mark < 80:
... print("Merit")
... elif mark >= 50 and mark < 60:
... print("Pass")
... else:
... print("Fail")
...
Distinction
>>>
>>> #--------------------------------------------------------
>>>
>>> ClassSize = int(input("Enter class size:"))
Enter class size: 24
>>>
>>> if ClassSize >= 25:
... print("Class size is too much")
... elif ClassSize >=10 and ClassSize < 25:
... print("Class size is acceptable")
... else:
... print("Class size is too small")
...
Class size is acceptable
>>>
>>> #--------------------------------------------------------
>>>
>>> price = int(input("Enter the price of the house:"))
Enter the price of the house: 650000
>>>
>>> taxRateA = 0.1
>>> taxRateB = 0.2
>>> taxRateC = 0.3
>>>
>>> if price > 500000:
... tax = price*taxRateC
... print("Tax rate C: ", tax)
... elif (price >=200000 and price <=500000):
... tax = price * taxRateB
... print("Tax rate B: ", tax)
... elif (price >100000 and price <=200000):
... tax = price * taxRateA
... print("Tax rate A: ", tax)
... else:
... print("No tax added")
...
Tax rate C: 195000.0
>>>
>>> price = int(input("Enter the price of the house:"))
Enter the price of the house: 75000
>>>
>>> if price > 500000:
... tax = price*taxRateC
... print("Tax rate C: ", tax)
... elif (price >=200000 and price <=500000):
... tax = price * taxRateB
... print("Tax rate B: ", tax)
... elif (price >100000 and price <=200000):
... tax = price * taxRateA
... print("Tax rate A: ", tax)
... else:
... print("No tax added")
...
No tax added
>>>
>>> price = int(input("Enter the price of the house:"))
Enter the price of the house: 350000
>>>
>>> if price > 500000:
... tax = price*taxRateC
... print("Tax rate C: ", tax)
... elif (price >=200000 and price <=500000):
... tax = price * taxRateB
... print("Tax rate B: ", tax)
... elif (price >100000 and price <=200000):
... tax = price * taxRateA
... print("Tax rate A: ", tax)
... else:
... print("No tax added")
...
Tax rate B: 70000.0
>>>
>>> price = int(input("Enter the price of the house:"))
Enter the price of the house: 425000
>>>
>>> if price > 500000:
... tax = price*taxRateC
... print("Tax rate C: ", tax)
... elif (price >=200000 and price <=500000):
... tax = price * taxRateB
... print("Tax rate B: ", tax)
... elif (price >100000 and price <=200000):
... tax = price * taxRateA
... print("Tax rate A: ", tax)
... else:
... print("No tax added")
...
Tax rate B: 85000.0
>>>
>>> price = int(input("Enter the price of the house:"))
Enter the price of the house: 900000
>>>
>>> if price > 500000:
... tax = price*taxRateC
... print("Tax rate C: ", tax)
... elif (price >=200000 and price <=500000):
... tax = price * taxRateB
... print("Tax rate B: ", tax)
... elif (price >100000 and price <=200000):
... tax = price * taxRateA
... print("Tax rate A: ", tax)
... else:
... print("No tax added")
...
Tax rate C: 270000.0
>>>
>>> #-------------------------------------------------------
-
>>>
>>> name = str(input("Enter name:"))
Enter name: Inta
>>> mark = int(input("Enter mark:"))
Enter mark: 55
>>>
>>> if mark >90 and mark <=100:
... print("You have gotten an A*",name)
... elif mark >=80 and mark <=90:
... print("You have gotten an A",name)
... elif mark >=70 and mark <=79:
... print("You have gotten a B",name)
... elif mark >=60 and mark <=69:
... print("You have gotten a C", name)
... elif mark >=50 and mark <=59:
... print("You have gotten a D",name)
... elif mark >=40 and mark <=49:
... print("You have gottten an E",name)
... else:
... print("You have gotten a U", name)
...
You have gotten a D Inta
>>>
>>> name = str(input("Enter name:"))
Enter name: Cokkie
>>> mark = int(input("Enter mark:"))
Enter mark: 24
>>>
>>> if mark >90 and mark <=100:
... print("You have gotten an A*",name)
... elif mark >=80 and mark <=90:
... print("You have gotten an A",name)
... elif mark >=70 and mark <=79:
... print("You have gotten a B",name)
... elif mark >=60 and mark <=69:
... print("You have gotten a C",name)
... elif mark >=50 and mark <=59:
... print("You have gotten a D",name)
... elif mark >=40 and mark <=49:
... print("You have gottten an E",name)
... else:
... print("You have gotten a U", name)
...
You have gotten a U Cokkie
>>>
>>> name = str(input("Enter name:"))
Enter name: Valerina
>>> mark = int(input("Enter mark:"))
Enter mark:92
>>>
>>> if mark >90 and mark <=100:
... print("You have gotten an A*",name)
... elif mark >=80 and mark <=90:
... print("You have gotten an A",name)
... elif mark >=70 and mark <=79:
... print("You have gotten a B",name)
... elif mark >=60 and mark <=69:
... print("You have gotten a C",name)
... elif mark >=50 and mark <=59:
... print("You have gotten a D",name)
... elif mark >=40 and mark <=49:
... print("You have gottten an E",name)
... else:
... print("You have gotten a U", name)
...
You have gotten an A* Valerina
>>>
>>> name = str(input("Enter name:"))
Enter name: Derek
>>> mark = int(input("Enter mark:"))
Enter mark: 86
>>>
>>> if mark >90 and mark <=100:
... print("You have gotten an A*",name)
... elif mark >=80 and mark <=90:
... print("You have gotten an A",name)
... elif mark >=70 and mark <=79:
... print("You have gotten a B",name)
... elif mark >=60 and mark <=69:
... print("You have gotten a C",name)
... elif mark >=50 and mark <=59:
... print("You have gotten a D",name)
... elif mark >=40 and mark <=49:
... print("You have gottten an E",name)
... else:
... print("You have gotten a U", name)
...
You have gotten an A Derek
>>>
>>> name = str(input("Enter name:"))
Enter name: Lunar
>>> mark = int(input("Enter mark:"))
Enter mark: 73
>>>
>>> if mark >90 and mark <=100:
... print("You have gotten an A*",name)
... elif mark >=80 and mark <=90:
... print("You have gotten an A",name)
... elif mark >=70 and mark <=79:
... print("You have gotten a B",name)
... elif mark >=60 and mark <=69:
... print("You have gotten a C",name)
... elif mark >=50 and mark <=59:
... print("You have gotten a D",name)
... elif mark >=40 and mark <=49:
... print("You have gottten an E",name)
... else:
... print("You have gotten a U", name)
...
You have gotten a B Lunar
>>>
>>> name = str(input("Enter name:"))
Enter name: Lyra
>>> mark = int(input("Enter mark:"))
Enter mark: 66
>>>
>>> if mark >90 and mark <=100:
... print("You have gotten an A*",name)
... elif mark >=80 and mark <=90:
... print("You have gotten an A",name)
... elif mark >=70 and mark <=79:
... print("You have gotten a B",name)
... elif mark >=60 and mark <=69:
... print("You have gotten a C",name)
... elif mark >=50 and mark <=59:
... print("You have gotten a D",name)
... elif mark >=40 and mark <=49:
... print("You have gottten an E",name)
... else:
... print("You have gotten a U", name)
...
You have gotten a C Lyra
>>>
>>> #---------------------------------------------------------
#-------------------------------------------#--------------------------------------
#--#--#--#--#--#--#-----#--#--#--#--#--#--^Z^Z

>>> def calculate_ticket_price(ticket_type, quantity):


... base_price = 250
... if ticket_type == "gold":
... price = base_price * 1.30
... elif ticket_type == "silver":
... price = base_price * 1.25
... elif ticket_type == "bronze":
... price = base_price * 1.20
... elif ticket_type == "standard":
... price = base_price
... else:
... return "Invalid ticket type"
...
... total_price = price * quantity
... return total_price
...
>>> def main():
... ticket_type = input("Enter the type of ticket you want to buy: ").lower()
... quantity = int(input("Enter the quantity of tickets you want to buy: "))
...
... total_price = calculate_ticket_price(ticket_type, quantity)
... if isinstance(total_price, str):
... print(total_price)
... else:
... print("Total price for {} {} ticket(s): ${}".format(quantity,
ticket_type.capitalize(), total_price))
...
>>> if __name__ == "__main__":
... main()
...
Enter the type of ticket you want to buy: Standard
Enter the quantity of tickets you want to buy: 100
Total price for 100 Standard ticket(s): $25000
>>>
>>> def calculate_ticket_price(ticket_type, quantity):
... base_price = 250
... if ticket_type == "gold":
... price = base_price * 1.30
... elif ticket_type == "silver":
... price = base_price * 1.25
... elif ticket_type == "bronze":
... price = base_price * 1.20
... elif ticket_type == "standard":
... price = base_price
... else:
... return "Invalid ticket type"
...
... total_price = price * quantity
... return total_price
...
>>> def main():
... ticket_type = input("Enter the type of ticket you want to buy: ").lower()
... quantity = int(input("Enter the quantity of tickets you want to buy: "))
...
... total_price = calculate_ticket_price(ticket_type, quantity)
... if isinstance(total_price, str):
... print(total_price)
... else:
... print("Total price for {} {} ticket(s): ${}".format(quantity,
ticket_type.capitalize(), total_price))
...
>>> if __name__ == "__main__":
... main()
...
Enter the type of ticket you want to buy: Gold
Enter the quantity of tickets you want to buy: 75
Total price for 75 Gold ticket(s): $24375.0
>>>
>>> def calculate_ticket_price(ticket_type, quantity):
... base_price = 250
... if ticket_type == "gold":
... price = base_price * 1.30
... elif ticket_type == "silver":
... price = base_price * 1.25
... elif ticket_type == "bronze":
... price = base_price * 1.20
... elif ticket_type == "standard":
... price = base_price
... else:
... return "Invalid ticket type"
...
... total_price = price * quantity
... return total_price
...
>>> def main():
... ticket_type = input("Enter the type of ticket you want to buy: ").lower()
... quantity = int(input("Enter the quantity of tickets you want to buy: "))
...
... total_price = calculate_ticket_price(ticket_type, quantity)
... if isinstance(total_price, str):
... print(total_price)
... else:
... print("Total price for {} {} ticket(s): ${}".format(quantity,
ticket_type.capitalize(), total_price))
...
>>> if __name__ == "__main__":
... main()
...
Enter the type of ticket you want to buy: Bronze
Enter the quantity of tickets you want to buy: 30
Total price for 30 Bronze ticket(s): $9000.0
>>>
>>> def calculate_ticket_price(ticket_type, quantity):
... base_price = 250
... if ticket_type == "gold":
... price = base_price * 1.30
... elif ticket_type == "silver":
... price = base_price * 1.25
... elif ticket_type == "bronze":
... price = base_price * 1.20
... elif ticket_type == "standard":
... price = base_price
... else:
... return "Invalid ticket type"
...
... total_price = price * quantity
... return total_price
...
>>> def main():
... ticket_type = input("Enter the type of ticket you want to buy: ").lower()
... quantity = int(input("Enter the quantity of tickets you want to buy: "))
...
... total_price = calculate_ticket_price(ticket_type, quantity)
... if isinstance(total_price, str):
... print(total_price)
... else:
... print("Total price for {} {} ticket(s): ${}".format(quantity,
ticket_type.capitalize(), total_price))
...
>>> if __name__ == "__main__":
... main()
...
Enter the type of ticket you want to buy: Silver
Enter the quantity of tickets you want to buy: 45
Total price for 45 Silver ticket(s): $14062.5
>>>
>>> def calculate_ticket_price(ticket_type, quantity):
... base_price = 250
... if ticket_type == "gold":
... price = base_price * 1.30
... elif ticket_type == "silver":
... price = base_price * 1.25
... elif ticket_type == "bronze":
... price = base_price * 1.20
... elif ticket_type == "standard":
... price = base_price
... else:
... return "Invalid ticket type"
...
... total_price = price * quantity
... return total_price
...
>>> def main():
... ticket_type = input("Enter the type of ticket you want to buy: ").lower()
... quantity = int(input("Enter the quantity of tickets you want to buy: "))
...
... total_price = calculate_ticket_price(ticket_type, quantity)
... if isinstance(total_price, str):
... print(total_price)
... else:
... print("Total price for {} {} ticket(s): ${}".format(quantity,
ticket_type.capitalize(), total_price))
...
>>> if __name__ == "__main__":
... main()
...
Enter the type of ticket you want to buy: Bronze
Enter the quantity of tickets you want to buy: 80
Total price for 80 Bronze ticket(s): $24000.0
>>>
>>>
#----------------------------------------------------------------------------------
-----
------
>>>
>>> def calculate_cost_per_km(transport_type):
... if transport_type.lower() == 'bus':
... cost_per_km = 2.5
... elif transport_type.lower() == 'taxi':
... cost_per_km = 7.5
... elif transport_type.lower() == 'uber':
... cost_per_km = 4
... else:
... return "Invalid transport type"
...
... return cost_per_km
...
>>> def main():
... transport_type = input("Enter the type of transport (Bus/Taxi/Uber): ")
... distance = float(input("Enter the distance of the ride in kilometers: "))
...
... cost_per_km = calculate_cost_per_km(transport_type)
... if isinstance(cost_per_km, str):
... print(cost_per_km)
... else:
... total_cost = cost_per_km * distance
... print("The cost of the ride per kilometer for {} is $
{:.2f}".format(transport_type, cost_per_km))
... print("Total cost for the {} ride: ${:.2f}".format(transport_type,
total_cost))
...
>>> if __name__ == "__main__":
... main()
...
Enter the type of transport (Bus/Taxi/Uber): Bus
Enter the distance of the ride in kilometers: 120
The cost of the ride per kilometer for Bus is $2.50
Total cost for the Bus ride: $300.00
>>>
>>> def calculate_cost_per_km(transport_type):
... if transport_type.lower() == 'bus':
... cost_per_km = 2.5
... elif transport_type.lower() == 'taxi':
... cost_per_km = 7.5
... elif transport_type.lower() == 'uber':
... cost_per_km = 4
... else:
... return "Invalid transport type"
...
... return cost_per_km
...
>>> def main():
... transport_type = input("Enter the type of transport (Bus/Taxi/Uber): ")
... distance = float(input("Enter the distance of the ride in kilometers: "))
...
... cost_per_km = calculate_cost_per_km(transport_type)
... if isinstance(cost_per_km, str):
... print(cost_per_km)
... else:
... total_cost = cost_per_km * distance
... print("The cost of the ride per kilometer for {} is $
{:.2f}".format(transport_type, cost_per_km))
... print("Total cost for the {} ride: ${:.2f}".format(transport_type,
total_cost))
...
>>> if __name__ == "__main__":
... main()
...
Enter the type of transport (Bus/Taxi/Uber): Taxi
Enter the distance of the ride in kilometers: 755
The cost of the ride per kilometer for Taxi is $7.50
Total cost for the Taxi ride: $5662.50
>>>
>>>
>>> def calculate_cost_per_km(transport_type):
... if transport_type.lower() == 'bus':
... cost_per_km = 2.5
... elif transport_type.lower() == 'taxi':
... cost_per_km = 7.5
... elif transport_type.lower() == 'uber':
... cost_per_km = 4
... else:
... return "Invalid transport type"
...
... return cost_per_km
...
>>> def main():
... transport_type = input("Enter the type of transport (Bus/Taxi/Uber): ")
... distance = float(input("Enter the distance of the ride in kilometers: "))
...
... cost_per_km = calculate_cost_per_km(transport_type)
... if isinstance(cost_per_km, str):
... print(cost_per_km)
... else:
... total_cost = cost_per_km * distance
... print("The cost of the ride per kilometer for {} is $
{:.2f}".format(transport_type, cost_per_km))
... print("Total cost for the {} ride: ${:.2f}".format(transport_type,
total_cost))
...
>>> if __name__ == "__main__":
... main()
...
Enter the type of transport (Bus/Taxi/Uber): Uber
Enter the distance of the ride in kilometers: 530
The cost of the ride per kilometer for Uber is $4.00
Total cost for the Uber ride: $2120.00
>>>
>>> def calculate_cost_per_km(transport_type):
... if transport_type.lower() == 'bus':
... cost_per_km = 2.5
... elif transport_type.lower() == 'taxi':
... cost_per_km = 7.5
... elif transport_type.lower() == 'uber':
... cost_per_km = 4
... else:
... return "Invalid transport type"
...
... return cost_per_km
...
>>> def main():
... transport_type = input("Enter the type of transport (Bus/Taxi/Uber): ")
... distance = float(input("Enter the distance of the ride in kilometers: "))
...
... cost_per_km = calculate_cost_per_km(transport_type)
... if isinstance(cost_per_km, str):
... print(cost_per_km)
... else:
... total_cost = cost_per_km * distance
... print("The cost of the ride per kilometer for {} is $
{:.2f}".format(transport_type, cost_per_km))
... print("Total cost for the {} ride: ${:.2f}".format(transport_type,
total_cost))
...
>>> if __name__ == "__main__":
... main()
...
Enter the type of transport (Bus/Taxi/Uber): Bus
Enter the distance of the ride in kilometers: 645
The cost of the ride per kilometer for Bus is $2.50
Total cost for the Bus ride: $1612.50
>>>
>>> def calculate_cost_per_km(transport_type):
... if transport_type.lower() == 'bus':
... cost_per_km = 2.5
... elif transport_type.lower() == 'taxi':
... cost_per_km = 7.5
... elif transport_type.lower() == 'uber':
... cost_per_km = 4
... else:
... return "Invalid transport type"
...
... return cost_per_km
...
>>> def main():
... transport_type = input("Enter the type of transport (Bus/Taxi/Uber): ")
... distance = float(input("Enter the distance of the ride in kilometers: "))
...
... cost_per_km = calculate_cost_per_km(transport_type)
... if isinstance(cost_per_km, str):
... print(cost_per_km)
... else:
... total_cost = cost_per_km * distance
... print("The cost of the ride per kilometer for {} is $
{:.2f}".format(transport_type, cost_per_km))
... print("Total cost for the {} ride: ${:.2f}".format(transport_type,
total_cost))
...
>>> if __name__ == "__main__":
... main()
...
Enter the type of transport (Bus/Taxi/Uber): Uber
Enter the distance of the ride in kilometers: 980
The cost of the ride per kilometer for Uber is $4.00
Total cost for the Uber ride: $3920.00
>>>
>>> #End of Task 4-Nested IF- H.A

You might also like