1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Jet001 [13]
3 years ago
12

python A pet shop wants to give a discount to its clients if they buy one or more pets. The discount is equal to 20 percent of t

he cost of the other items, but not the pets. Implement a function def discount(prices, isPet, nItems) The function receives information about a particular sale. For the ith item, prices[i] is the price before any discount, and isPet[i] is true if the item is a pet. Write a program that prompts a cashier to enter each price and then a Y for a pet or N for another item. Use a price of –1 as a sentinel. Save the inputs in a list. Call the function that you implemented, and display the discount.
Computers and Technology
1 answer:
Artyom0805 [142]3 years ago
8 0

Answer:

The following are the program in the Python Programming Language.

#define function

def discount(prices, isPet, nItems):

 # declare and initialize variables to 0

 i = 0

 cost = 0

 pets = 0

 item = 0

 item_Cost = 0

 #set the while loop

 while(i < nItems):

   #check the items of the variable

   if isPet[i]:

     #add and initialize in the cost

     cost += prices[i]

     #increament in the variable by 1

     pets += 1

   #otherwise

   else:

     #add and initialize in the item_Cost

     item_Cost += prices[i]

     #increament in the variable by 1

     item += 1

   #then increment in the variable by 1

   i += 1

 #check the pet is greater than equal to 1  

 #and item is greater than equal to 5

 if(pets >= 1 and item >=5):

   #then, print the message

   print("You receive discount")

   #set discount of the items

   discount = 0.2 * item_Cost

   # calculate bill after deducting discount

   bill = cost + item_Cost - discount

   #print the bill

   print("Final Bill amount is", bill)

 #otherwise

 else:

   #print the message

   print("You do not receive any discount")

   #calculate bill without deducting discount

   bill = cost + item_Cost

   #print the final bill

   print("Final Bill amount is", bill)

#set empty list type variables

price = []

pet = []

#set the infinite loop

while True:

 #get input from the user

 sprice = int(input("Enter the price (-1 to quit): "))

 #check that price is not equal to the -1

 if(sprice != -1):

   #add price in the list

   price.append(sprice)

   #ask for choice from the user

   choice = input("Is it a pet (Y / N)? ")

   #check the choice of the user is y or Y

   if(choice == 'Y' or choice == 'y'):

     # then, add in the pet

     pet.append(True)

   #otherwise

   else:

     #not add in the pet

     pet.append(False)

   print("")

 #break the loop

 else:

   break

#declare variable that store the length

items = len(price)

#call and initialize the variable

discount(price, pet, items)

<u>Output</u>:

Enter the price (-1 to quit): 96

Is it a pet (Y / N)? y

Enter the price (-1 to quit): 69

Is it a pet (Y / N)? n

Enter the price (-1 to quit): 41

Is it a pet (Y / N)? n

Enter the price (-1 to quit): 52

Is it a pet (Y / N)? n

Enter the price (-1 to quit): 96

Is it a pet (Y / N)? n

Enter the price (-1 to quit): 74

Is it a pet (Y / N)? n

Enter the price (-1 to quit): -1

You receive discount

Final Bill amount is 361.6

Explanation:

<u>The following are the description of the program</u>.

  • Firstly, define the function 'discount()' and pass the arguments 'prices', 'isPet' and 'nItems' in its parameter.
  • Then, declare and initialize the variables 'i' to 0, 'item_Cost' to 0
  • , item to 0, 'cost' to 0 and 'pets' to 0.
  • Then, set the while loop to add the price of the items and the cost of the pets.
  • Set the if-else conditional statement to check the pet is greater than equal to 1 and the items are greater than equal to 5 then, set the discount and print the bill after deduction.
  • Otherwise, print the bill without deduction.
  • Finally, set two list type variable then, set the infinite while loop that gets input from the user and check that the variable is not equal to -1 then append the data in the list then again check the user input then append in pet otherwise not append in pet and break the loop. Then, set the variable that stores the length of the price and call the following function by passing arguments in its parameter.
You might be interested in
For this programming assignment you will implement the Naive Bayes algorithm from scratch and the functions to evaluate it with
DanielleElmas [232]

Bayes’ Theorem provides a way that we can calculate the probability of a piece of data belonging to a given class, given our prior knowledge.

P(class|data) = (P(data|class) * P(class)) / P(data)

Where P(class|data) is the probability of class given the provided data.

Explanation:

  • Naive Bayes is a classification algorithm for binary  and multiclass classification problems.
  • It is called Naive Bayes or idiot Bayes because the calculations of the probabilities for each class are simplified to make their calculations tractable.

This Naive Bayes tutorial is broken down into 5 parts:

Step 1: Separate By Class :  Calculate the probability of data by the class they belong to, the so-called base rate. Separate our training data by class.

Step 2: Summarize Dataset : The two statistics we require from a given dataset are the mean and the standard deviation

The mean is the average value and can be calculated using :

mean = sum(x)/n * count(x)

Step 3: Summarize Data By Class : Statistics from our training dataset organized by class.

Step 4: Gaussian Probability Density Function : Probability or likelihood of observing a given real-value. One way we can do this is to assume that the values are drawn from a distribution, such as a bell curve or Gaussian distribution.

Step 5: Class Probabilities :  The statistics calculated from our training data to calculate probabilities for new data.  Probabilities are calculated separately for each class. This means that we first calculate the probability that a new piece of data belongs to the first class, then calculate the second class, on for all the classes.

8 0
3 years ago
How many bytes are in 1 kilobyte of storage
topjm [15]

Answer:

1000

Explanation I SEARCHED IT Up

5 0
4 years ago
The Save command saves your changes silently without additional prompts, using the same save settings; the Save As command reope
kirza4 [7]

The "Save command" saves your changes <u>silently</u> without additional prompts and it uses the same save settings while the "Save As command" <u>reopens</u> the Save screen: True.

What is the Save command?

A Save command can be defined as a type of command associated with the file menu of a software application and it causes a copy of the current file to be created and stored to a specific location on a computer system.

<h3>What is the Save as command?</h3>

A Save command can be defined as a type of command associated with the file menu of a software application and it causes a copy of the current file to be created and stored to a different location, file name, and/or file type.

In conclusion, the "Save command" saves your changes <u>silently</u> without additional prompts and it uses the same save settings while the "Save As command" <u>reopens</u> the Save screen, so as to enable you make different choices.

Read more on Save command here: brainly.com/question/16852455

5 0
3 years ago
Using a while loop, create an algorithm extractDigits that prints the individual digits of a positive integer.
sergiy2304 [10]

Answer:

The algorithm is as follows

1. Start

2. Declare Integer N

3. Input N

4. While N > 0:

4.1    Print(N%10)

4.2   N = N/10

5. Stop

Explanation:

This line starts the algorithm

1. Start

This declares an integer variable

2. Declare Integer N

Here, the program gets user input N

3. Input N

The while iteration begins here and it is repeated as long as N is greater than 0

4. While N > 0:

This calculates and prints N modulus 10; Modulus of 10 gets the individual digit of the input number

4.1    Print(N%10)

This remove the printed digit

4.2   N = N/10

The algorithm ends here

5. Stop

<u>Bonus:</u>

The algorithm in Python is as follows:

<em>n = 102</em>

<em>while n>0:</em>

<em>     print(int(n%10))</em>

<em>     n= int(n/10)</em>

<em>    </em>

8 0
3 years ago
Intellectual property rights protect people’s and organization’s ideas and other intellectual assets. However, in certain cases,
Katarina [22]

Answer:

negative effect

Explanation:

its right on edg

8 0
3 years ago
Other questions:
  • What is the main idea of this article? Please someone help me. I will give brainliest answer
    7·1 answer
  • What does it mean to calculate frequencies within a dataset
    7·2 answers
  • For connection to place on any network you must have a set of standards?<br> O True<br> O False
    8·1 answer
  • What does technological convergence mean, with examples?
    10·1 answer
  • Fill the validateForm function to check that the phone number contains a number (use the isNaN function) and that the user name
    8·1 answer
  • We have the following class:
    6·1 answer
  • Which of the following is considered proper typing technique?
    15·1 answer
  • Declare a Scanner reference variable fileInput, and assign it a newly created Scanner object that is associated with a file name
    10·1 answer
  • Giusp minfg gấp vs ạ đáp án thôi nhé
    15·1 answer
  • Which would you use to get the number of elements in a dictionary?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!