0% found this document useful (0 votes)
22 views14 pages

Doc

ff

Uploaded by

fls73081
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)
22 views14 pages

Doc

ff

Uploaded by

fls73081
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/ 14

import math

# Function to calculate and output details for each order

def calculate_order(order_num, price_per_sqft, width, length):

# Calculate room area in square feet

room_area = width * length

# Calculate carpet cost with 20% additional for waste

carpet_cost = room_area * price_per_sqft * 1.2

# Calculate labor cost ($0.75 per actual square foot)

labor_cost = room_area * 0.75

# Calculate sales tax (7% on carpet and labor cost)

tax = 0.07 * (carpet_cost + labor_cost)

# Calculate total cost

total_cost = carpet_cost + labor_cost + tax

# Output the details for the order

print(f"Order #{order_num}")

print(f"Room: {room_area} sq ft")


print(f"Carpet: ${carpet_cost:.2f}")

print(f"Labor: ${labor_cost:.2f}")

print(f"Tax: ${tax:.2f}")

print(f"Cost: ${total_cost:.2f}\n")

# Return the total cost for the order

return total_cost

# Main program

if __name__ == "__main__":

total_sales = 0 # Initialize total sales

# Step 4 & 5: Handle up to three orders

num_orders = 3 # Number of orders to handle (change this to 1 or 2 as needed)

for i in range(1, num_orders + 1):

# Read inputs for each order

print(f"Enter details for Order #{i}:")

price_per_sqft, width, length = map(float, input().split())

# Calculate and output order details


order_total = calculate_order(i, price_per_sqft, int(width), int(length))

# Add to total sales

total_sales += order_total

# Output total sales

print(f"Total Sales: ${total_sales:.2f}")

Program 2 :

import math

# Step 1: Calculate number of pizzas and cost

def calculate_pizza_cost(people, avg_slices, pizza_cost):

slices_needed = people * avg_slices

pizzas_needed = math.ceil(slices_needed / 8) # Each pizza has 8 slices

total_pizza_cost = pizzas_needed * pizza_cost

return pizzas_needed, total_pizza_cost

# Step 2: Calculate tax and delivery charges

def calculate_tax_and_delivery(total_cost):

tax = total_cost * 0.07 # 7% tax

delivery_charge = (total_cost + tax) * 0.20 # 20% delivery charge


return tax, delivery_charge

# Step 3: Calculate total cost including tax and delivery

def calculate_total_cost(pizza_cost, tax, delivery_charge):

return pizza_cost + tax + delivery_charge

# Step 4: Process a single party

def process_party(party_name, people, avg_slices, pizza_cost):

print(f"{party_name}")

pizzas_needed, total_pizza_cost = calculate_pizza_cost(people, avg_slices, pizza_cost)

print(f"{pizzas_needed} Pizzas: ${total_pizza_cost:.2f}")

tax, delivery_charge = calculate_tax_and_delivery(total_pizza_cost)

print(f"Tax: ${tax:.2f}")

print(f"Delivery: ${delivery_charge:.2f}")

total_cost = calculate_total_cost(total_pizza_cost, tax, delivery_charge)

print(f"Total: ${total_cost:.2f}\n")

return total_cost
# Step 5: Combine totals for all parties

def main():

weekend_total = 0.0

# Input for Friday

friday_input = input("Enter Friday inputs (people avg_slices pizza_cost): ")

friday_people, friday_slices, friday_pizza_cost = map(float, friday_input.split())

weekend_total += process_party("Friday Night Party", int(friday_people), friday_slices,


friday_pizza_cost)

# Input for Saturday

saturday_input = input("Enter Saturday inputs (people avg_slices pizza_cost): ")

saturday_people, saturday_slices, saturday_pizza_cost = map(float,


saturday_input.split())

weekend_total += process_party("Saturday Night Party", int(saturday_people),


saturday_slices, saturday_pizza_cost)

# Input for Sunday

sunday_input = input("Enter Sunday inputs (people avg_slices pizza_cost): ")

sunday_people, sunday_slices, sunday_pizza_cost = map(float, sunday_input.split())

weekend_total += process_party("Sunday Night Party", int(sunday_people),


sunday_slices, sunday_pizza_cost)

# Weekend total
print(f"Weekend Total: ${weekend_total:.2f}")

# Run the program

if __name__ == "__main__":

main()

Program 3

from math import ceil # needed for Step 3

# Step 1: Read input values and calculate the wall area

# Input values

wall_height = float(input("Enter wall height (in feet): "))

wall_width = float(input("Enter wall width (in feet): "))

paint_can_cost = float(input("Enter the cost of one paint can (in dollars): "))

# Calculate wall area

wall_area = wall_height * wall_width

print(f"Wall area: {wall_area:.1f} sq ft")

# Step 2: Calculate the amount of paint needed

paint_coverage = 350.0 # 1 gallon covers 350 square feet

paint_needed = wall_area / paint_coverage


print(f"Paint needed: {paint_needed:.3f} gallons")

# Step 3: Calculate the number of cans needed

cans_needed = ceil(paint_needed)

print(f"Cans needed: {cans_needed} can(s)")

# Step 4: Calculate the paint cost, sales tax, and total cost

paint_cost = cans_needed * paint_can_cost

sales_tax_rate = 0.07 # 7% sales tax

sales_tax = paint_cost * sales_tax_rate

total_cost = paint_cost + sales_tax

# Output the costs

print(f"Paint cost: ${paint_cost:.2f}")

print(f"Sales tax: ${sales_tax:.2f}")

print(f"Total cost: ${total_cost:.2f}")

Program 4

# Step 1: Input data and calculate AGI

wages = int(input("Enter wages: "))

taxable_interest = int(input("Enter taxable interest: "))

unemployment_compensation = int(input("Enter unemployment compensation: "))


status = int(input("Enter status (1=single, 2=married): "))

taxes_withheld = int(input("Enter taxes withheld: "))

# Calculate AGI

agi = wages + taxable_interest + unemployment_compensation

print(f"AGI: ${agi:,}")

# Check if AGI exceeds the limit

if agi > 120_000:

print("Error: Income too high to use this form")

exit()

# Step 2: Calculate deduction and taxable income

if status == 2: # Married

deduction = 24_000

elif status == 1: # Single

deduction = 12_000

else: # Invalid status defaults to single

status = 1

deduction = 12_000

taxable_income = agi - deduction


if taxable_income < 0:

taxable_income = 0

print(f"Deduction: ${deduction:,}")

print(f"Taxable income: ${taxable_income:,}")

# Step 3: Calculate federal tax

federal_tax = 0

if status == 1: # Single

if taxable_income <= 10_000:

federal_tax = taxable_income * 0.10

elif taxable_income <= 40_000:

federal_tax = 1_000 + (taxable_income - 10_000) * 0.12

elif taxable_income <= 85_000:

federal_tax = 4_600 + (taxable_income - 40_000) * 0.22

else:

federal_tax = 14_500 + (taxable_income - 85_000) * 0.24

elif status == 2: # Married

if taxable_income <= 20_000:

federal_tax = taxable_income * 0.10

elif taxable_income <= 80_000:

federal_tax = 2_000 + (taxable_income - 20_000) * 0.12


else:

federal_tax = 9_200 + (taxable_income - 80_000) * 0.22

federal_tax = round(federal_tax)

print(f"Federal tax: ${federal_tax:,}")

# Step 4: Calculate tax due or refund

tax_due = federal_tax - taxes_withheld

if tax_due > 0:

print(f"Tax due: ${tax_due:,}")

else:

print(f"Tax refund: ${abs(tax_due):,}")

Program 5

# Constants for maximum points

HOMEWORK_MAX = 800.0

QUIZZES_MAX = 400.0

MIDTERM_MAX = 150.0

FINAL_MAX = 200.0

# Step 1: Read student status and validate input


student_status = input("Enter student status (UG, G, or DL): ").strip()

# Validate student status

if student_status not in ["UG", "G", "DL"]:

print("Error: student status must be UG, G or DL")

exit()

# Read scores for homework, quizzes, midterm, and final

homework_points, quizzes_points, midterm_points, final_points = map(

float, input("Enter points for homework, quizzes, midterm, and final (space-separated):
").split()

# Calculate percentage for each category

homework = (homework_points / HOMEWORK_MAX) * 100

quizzes = (quizzes_points / QUIZZES_MAX) * 100

midterm = (midterm_points / MIDTERM_MAX) * 100

final_exam = (final_points / FINAL_MAX) * 100

# Output category averages

print(f"Homework: {homework:2.1f}%")

print(f"Quizzes: {quizzes:2.1f}%")

print(f"Midterm: {midterm:2.1f}%")
print(f"Final Exam: {final_exam:2.1f}%")

# Step 2: Cap averages at 100%

homework = min(homework, 100.0)

quizzes = min(quizzes, 100.0)

midterm = min(midterm, 100.0)

final_exam = min(final_exam, 100.0)

# Output capped averages

print(f"After capping averages:")

print(f"Homework: {homework:2.1f}%")

print(f"Quizzes: {quizzes:2.1f}%")

print(f"Midterm: {midterm:2.1f}%")

print(f"Final Exam: {final_exam:2.1f}%")

# Step 3: Calculate the course average based on student status

if student_status == "UG": # Undergraduate

course_average = (homework * 0.20 + quizzes * 0.20 +

midterm * 0.30 + final_exam * 0.30)

elif student_status == "G": # Graduate

course_average = (homework * 0.15 + quizzes * 0.05 +

midterm * 0.35 + final_exam * 0.45)


elif student_status == "DL": # Distance Learner

course_average = (homework * 0.05 + quizzes * 0.05 +

midterm * 0.40 + final_exam * 0.50)

# Output course average

print(f"{student_status} average: {course_average:2.1f}%")

You might also like