0% found this document useful (0 votes)
14 views2 pages

Assignment

The document contains Python code that takes user input for various calculations including name, numbers, marks, area, refund amount, mileage, meal costs, integers, and time spent on activities. It then performs calculations and prints outputs such as sums, averages, percentages. There are over 20 examples of taking input, performing calculations, and printing outputs.

Uploaded by

zhuhu2002
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)
14 views2 pages

Assignment

The document contains Python code that takes user input for various calculations including name, numbers, marks, area, refund amount, mileage, meal costs, integers, and time spent on activities. It then performs calculations and prints outputs such as sums, averages, percentages. There are over 20 examples of taking input, performing calculations, and printing outputs.

Uploaded by

zhuhu2002
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/ 2

name = input("Enter your name: ")

print("Hello, " + name + "!")

num1 = float(input("Enter the first number: "))


num2 = float(input("Enter the second number: "))
sum = num1 + num2
print("The sum of", num1, "and", num2, "is", sum)

mark1 = float(input("Enter mark 1: "))


mark2 = float(input("Enter mark 2: "))
mark3 = float(input("Enter mark 3: "))
mark4 = float(input("Enter mark 4: "))
average = (mark1 + mark2 + mark3 + mark4) / 4
print("The average mark is", average)

width = float(input("Enter the width of the room (in feet): "))


length = float(input("Enter the length of the room (in feet): "))
area = width * length
print("The area of the room is", area, "square feet.")

length = float(input("Enter the length of the field (in feet): "))


width = float(input("Enter the width of the field (in feet): "))
area = length * width
acres = area / 43560
print("The area of the field is", acres, "acres.")

small_containers = int(input("Enter the number of containers holding one liter or less: "))
large_containers = int(input("Enter the number of containers holding more than one liter: "))
refund = (0.10 * small_containers) + (0.25 * large_containers)
print("The refund amount is $", format(refund, ".2f"))

mileage = float(input("Enter mileage in miles: "))


kilometers = mileage * 1.61
print("The mileage in kilometers is", kilometers, "km.")

meal_cost = float(input("Enter the cost of the meal: "))


tax_rate = 0.10
tip_rate = 0.18
tax_amount = meal_cost * tax_rate
tip_amount = meal_cost * tip_rate
total_cost = meal_cost + tax_amount + tip_amount
print("Tax amount: ${:.2f}".format(tax_amount))
print("Tip amount: ${:.2f}".format(tip_amount))
print("Total cost: ${:.2f}".format(total_cost))
a = int(input("Enter the first integer (a): "))
b = int(input("Enter the second integer (b): "))
sum = a + b
difference = a - b
product = a * b
quotient = a / b
print("Sum of a and b:", sum)
print("Difference of a and b:", difference)
print("Product of a and b:", product)
print("Quotient of a and b:", quotient)

sleeping = float(input("Enter the amount of time spent sleeping: "))


watching_tv = float(input("Enter the amount of time spent watching TV: "))
studying = float(input("Enter the amount of time spent studying: "))
exercising = float(input("Enter the amount of time spent exercising: "))
total_time = sleeping + watching_tv + studying + exercising
sleeping_percentage = (sleeping / total_time) * 100
watching_tv_percentage = (watching_tv / total_time) * 100
studying_percentage = (studying / total_time) * 100
exercising_percentage = (exercising / total_time) * 100
print("Total time: ", total_time)
print("Percentage of time spent sleeping: {:.2f}%".format(sleeping_percentage))
print("Percentage of time spent watching TV: {:.2f}%".format(watching_tv_percentage))
print("Percentage of time spent studying: {:.2f}%".format(studying_percentage))
print("Percentage of time spent exercising: {:.2f}%".format(exercising_percentage))

You might also like