47.4k views
1 vote
Help with python? Need help with programming something short.

Help with python? Need help with programming something short.-example-1

1 Answer

5 votes

Answer:

def main():

# Get the make and model of the phone

make_and_model = input("Enter in the cell phone make and model: ")

# Get the price of the phone

price_string = input("Enter in the price of the phone in dollars: $")

price = float(price_string)

# Get the price of the warranty

warranty_string = input("Enter in the price of the warranty in dollars: $")

warranty = float(warranty_string)

# Calculate the sales tax

tax = (price + warranty) * 0.06

# Calculate the shipping cost

shipping = price * 0.017

# Calculate the total amount due

total = price + warranty + tax + shipping

# Display the receipt

print("Receipt:")

print("The cellphone purchased is:", make_and_model)

print("The purchase price is: $%.2f" % price)

print("The warranty cost is: $%.2f" % warranty)

print("The tax is: $%.2f" % tax)

print("The shipping cost is: $%.2f" % shipping)

print("The amount due is: $%.2f" % total)

# Call the main function

main()

Step-by-step explanation:

First, we define a function called main. This function will contain all of the code for the program.

We start by using the input function to get the make and model of the phone from the user. We store the user's response in a variable called make_and_model.

Then, we use the input function again to get the price of the phone from the user. However, this time we store the user's response as a string in the variable price_string. We then convert this string to a floating point number and store it in the variable price.

Next, we use the input function to get the price of the warranty from the user. Like before, we store the user's response as a string in the variable warranty_string and then convert it to a floating point number and store it in the variable warranty.

Now that we have the price of the phone and the price of the warranty, we can calculate the sales tax. We do this by multiplying the sum of the price and the warranty by 0.06 and storing the result in the variable tax.

We also need to calculate the shipping cost. We do this by multiplying the price of the phone by 0.017 and storing the result in the variable shipping.

Finally, we can calculate the total amount due by adding up the price of the phone, the price of the warranty, the sales tax, and the shipping cost and storing the result in the variable total.

To display the receipt, we use the print function to output each of the required items: the make and model, the purchase price, the warranty cost, the tax, the shipping cost, and the total amount due. All of these values are formatted as currency using the %.2f format specifier.

At the end of the main function, we call it to run the program.

User Robert Cotterman
by
6.9k points