Question
***Can not use any string methods or user-defined method***** ****Must use the most basic python**** The grocery store owner designed a very strange pricing regulation
***Can not use any string methods or user-defined method*****
****Must use the most basic python****
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 table 4. 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 it is 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 in developing NerdyGrocery. The same logic is applied to the inputs provided in example 2. Note that your program input and output format should be exactly the same as the format of the examples shown in Table 4.
Table 4: The NerdyGrocery Sample Inputs and Outputs
EX 1 | EX 2 |
5 | 4 |
1 | 17 |
7 | 12 |
6 | 1 |
12 | 20 |
2 | 8 |
4 |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started