Question

In: Computer Science

I keep getting minor errors I can't figure out and I don't know how to convert...

I keep getting minor errors I can't figure out and I don't know how to convert decimal .10 to percentage 10% either.  
With these functions defined now expand the program for a company who gives discounts on items bought in bulk.
Create a main function and inside of it ask the user how many different items they are buying.
For each item have the user input a price and quantity, validating them with the functions that you wrote.
Use your discount function to find the discount for each item's quantity and calculate the discounted price.
Print the discounted price in $9,999.99 format

Sum the discounted totals for all items and display this grand total at the end.
Print the percentages in 99.9% format.

In addition to summing the discounted totals, also sum the un-discounted totals.
At the end display both of these values and then calculate and print the overall percentage saved in 99.9% format.

def discount ():
discount = 0.00
if quantity >= 0 and quantity <= 19 :
discount = 0.00
if quantity >= 20 and quantity >= 49 :
discount = 0.05
if quantity >= 50 and quantity <= 99 :
discount = 0.08
if quantity >= 100 :
discount = 0.10
return discount
# user input quantity
def quantity ():
quantity = 0
quantity = int (input ('What is the quantity? '))
while quantity < 1 or quantity > 2000 :
print ('Error, Please enter a quantity between 1 and 2000.')
quantity = int (input ('What is the quantity? '))
return quantity
# user input price
def price ():
price = 0.0
price = float (input ('What is the price? '))
while price < 0.0 :
print ('Error, the price must be greater than $0.00')
price = float (input ('What is the price? '))
return price
# main
def main ():
for i in range (items)   
items = int (input ('How many different items are you purchasing? '))
quantity ()
discount ()
price ()
Total_price = sum (price)
Total_discount = sum (discount)
Discounted_price = price - (price * discount)
Total_Discounted_price = Total_price - (Total_price * Total_discount)
print ('For item ',i +1,,' ' Discounted_price, ' with a ', discount, format (.2f, sep=''))
print ('Total order is ', Total_Discounted_price, ' with a ', Total_discount, format (.2f, sep=''))
#initiate
main ()

Solutions

Expert Solution

def discount (q):
d = 0.00
if q >= 0 and q <= 19 :
d = 0.00
if q >= 20 and q >= 49 :
d = 0.05
if q >= 50 and q <= 99 :
d = 0.08
if q >= 100 :
d = 0.10
return d
# user input quantity
def quantity ():
q = 0
q = int (input ('What is the quantity? '))
while q < 1 or q > 2000 :
print ('Error, Please enter a quantity between 1 and 2000.')
q = int (input ('What is the quantity? '))
return q
# user input price
def price ():
p = 0.0
p = float (input ('What is the price? '))
while p < 0.0 :
print ('Error, the price must be greater than $0.00')
p = float (input ('What is the price? '))
return p
# main
def main ():
items = int (input ('How many different items are you purchasing? '))
for i in range(items):
q=quantity()
d=discount(q)
p=price()
Total_price =p*q
Total_discount = d*Total_price
Discounted_price = p - (p * d)
Total_Discounted_price = Total_price - ( Total_discount)
print ('For item ',i +1,' ' ,Discounted_price, ' with a discount', round(d,2))
print ('Total order is ', Total_Discounted_price, ' with a discount', round(Total_discount,2))
#initiate
main ()

Screenshots:

The code is edited and the errors are removed.

Please follow the output attached below for reference and proper indentation.


Related Solutions

In java, I keep getting the error below and I can't figure out what i'm doing...
In java, I keep getting the error below and I can't figure out what i'm doing wrong. Any help would be appreciated. 207: error: not a statement allocationMatrix[i][j];
I am getting an error at linen 57 and can't figure out how to fix it....
I am getting an error at linen 57 and can't figure out how to fix it. // Java program to read a CSV file and display the min, max, and average of numbers in it. import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Scanner; public class Main {     // method to determine and return the minimum number from the array     public static int minimum(int numbers[])     {         int minIdx = 0;         for(int i=1;i<numbers.length;i++)         {             if((minIdx...
I keep getting an error that I cannot figure out with the below VS2019 windows forms...
I keep getting an error that I cannot figure out with the below VS2019 windows forms .net framework windows forms error CS0029 C# Cannot implicitly convert type 'bool' to 'string' It appears to be this that is causing the issue string id; while (id = sr.ReadLine() != null) using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; namespace Dropbox13 { public partial class SearchForm : Form { private List allStudent = new List(); public SearchForm() { InitializeComponent(); } private void SearchForm_Load(object...
While getting ready for work one morning I encountered something I can't figure out. I wear...
While getting ready for work one morning I encountered something I can't figure out. I wear glasses and without them objects are blurry unless I get very close, within a few inches. I always take my glasses off when I blow dry my hair in the morning. While standing in front of the mirror in my bathroom I can see a reflection of the tv screen in the bedroom. It is blurry when my glasses are off and much clearer...
I don't know why I keep getting the following error: AttributeError: 'tuple' object has no attribute...
I don't know why I keep getting the following error: AttributeError: 'tuple' object has no attribute 'size' I am using python in Anaconda. import numpy as np def information_gain(x_array, y_array): parent_entropy = entropy(x_array) split_dict = split(y_array) for val in split_dict.values(): freq = val.size / x_array.size child_entropy = entropy([x_array[i] for i in val]) parent_entropy -= child_entropy* freq return parent_entropy x = np.array([0, 1, 0, 1, 0, 1]) y = np.array([0, 1, 0, 1, 1, 1]) print(round(information_gain(x, y), 4)) x = np.array([0,...
I am supposed to map out the following and can't figure out how to do it!...
I am supposed to map out the following and can't figure out how to do it! Can somebody help? The experiment has to do with determining the simplest formula of potassium chlorate and to determine the original amount of potassium chlorate in a potassium chlorate-potassium chloride mixture by measuring the oxygen lost from decomposition. The chemical reaction is 2KClO3(s) ------> 2KCL(s) + 3 O2(g) I am supposed to map out 1. Mass of oxygen lost in the first part 2....
I working on this program in C++ and I keep getting 20 errors of the same...
I working on this program in C++ and I keep getting 20 errors of the same type again.cpp:36:11: error: use of undeclared identifier 'Polynomial' int main() { // create a list of polinomials vector<Polynomial> polynomials; // welcome message cout << "Welcome to Polynomial Calculator" << endl; int option = 0; while (option != 6) { // display menu displayMenu(); // get user input; cin >> option; if (option == 1) { cout << "Enter a polynomial :" << endl; string...
I'm getting an error message with this code and I don't know how to fix it...
I'm getting an error message with this code and I don't know how to fix it The ones highlighted give me error message both having to deal Scanner input string being converted to an int. I tried changing the input variable to inputText because the user will input a number and not a character or any words. So what can I do to deal with this import java.util.Scanner; public class Project4 { /** * @param args the command line arguments...
I can't figure out how to create the decision tree with the sending a messaged situation!...
I can't figure out how to create the decision tree with the sending a messaged situation! The crew of Endurance can visit two planets (Mann’s and Edmunds’). They can choose to visit neither planets, one of the two planets, or both planets. The characteristics of Mann’s planet are below: • 30% chance of finding a perfectly habitable planet • can support all of Earth’s current population if it is • can support none of Earth’s population if it is not...
I can't seem to figure out what the hybridization of PF6(-) is. could someone explain how...
I can't seem to figure out what the hybridization of PF6(-) is. could someone explain how to find it correctly for me?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT