Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming language:python A programmers wife tells him, While youre at the grocery store, buy some eggs.He never comes back. Now, imagine a situation in which

Programming language:python

A programmers wife tells him, "While youre at the grocery store, buy some eggs."He never comes back.

Now, imagine a situation in which such a programmer does shopping in a grocery owned by a nerdy!Things can even get more complicated, right? Joking aside, in this part , you as a programmer are supposed to help a nerdy owner of a grocery by writing a program called NerdyGrocery as follows.

The grocery store owner designed a very strange pricing regulation for their products, in which the price of a product only depends on its weight.

If the weight of a product is a prime number, the price of the product is equal to the number of prime numbers less than the weight of the product. For example, if the weight of a product is 7,the price would be $3, because there are three prime numbers less than 7, which are 2, 3, 5.

If the weight of a product is not a prime number, the price is equal to the number of prime divisors of the weight. For example, if the weight of a product is 6, the price would be $2, because 6 has two prime divisors, which are 2 and 3.Moreover, the grocery offers a discount based on the total price of a customers shopping:

If the total price of shopping is a prime number, the grocery offers a discount equal to the number of prime numbers less than the total price.

If the total price of shopping is not a prime number, the grocery offers a discount equal to the number of prime divisors of the total price.

NerdyGrocery helps the grocery and its customers to facilitate the payment process as follows:

NerdyGrocery first, receives the number of products in the customers shopping basket. Lets call this number n. NerdyGrocery assumes the user only enters positive integers (greater than 0).

Subsequently, NerdyGrocery receives the weight of each product in n separate lines. NerdyGrocery assumes the user only enters positive integers (greater than 0).

NerdyGrocery calculates the total price of the customers shopping considering the above-mentioned regulation and after applying the corresponding discount.

Two examples are shown in the table below. In example 1, the customer had 5 products in their basket. The weight of the first product is one. 1 is not a prime number and doesnt have any prime divisors, so its price is $0. The weight of the next product is 7, and as explained earlier, its cost is $3. The next product weighs 6, and it costs $2, as explained above. The next items weight is 12, which is not a prime number.

The number of prime divisors of 12 is 2, so its price is $2. Finally, the last product weight is 2, and itis a prime number. There isnt any prime number less than 2, so it costs $0. Therefore, the total price is $7.Since the total price is a prime number, the total discount is equal to the number of prime numbers less than 7, which is 3. Consequently, the total price after applying the discount will be $7 $3 = $4 as printed in the last line as the expected output of NerdyGrocery for this example.

You are not allowed to use any user-defined modules or python built in methods in developing NerdyGrocery. Note that your program input and output format should be exactly the same as the format of the examples shown in the table below.

Example 1

Example 2

5

1

7

6

12

2

4

4

17

12

1

20

8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

4. Does cultural aptitude impact ones emotional intelligence?

Answered: 1 week ago

Question

7. Do the organizations social activities reflect diversity?

Answered: 1 week ago