It's a Python coding problem, what should I do?ㅜㅜ

Asked 2 years ago, Updated 2 years ago, 117 views

Fruit stores sell pears, grapefruit, melon, and persimmons Stock quantity and unit price in advance fruit = {'bae': [2, 1000], 'grapefruit': [1, 2000], ' Meron': [1, 8000], 'Gam': [6, 800]} stored in Output results as follows: Write a script to do
① If the fruit is sold by entering the name of the fruit, subtract one from the inventory
② Read inventory information and unit price as many as possible in the dictionary for 5 units If there are less than 5 items, purchase them.

Output

What fruit do you want to eat? : Plum
Plums are not ready
Buy at least five per fruit
The total amount required for purchase is: 43,000 won

What fruit do you want to eat? : Melon
Enjoy your melon
Buy at least five per fruit
The total amount required for purchase is: 51,000 won

Could you just tell me what to do?

python coding

2022-09-22 18:07

2 Answers

What you need seems to be a programmatic transformation of everyday behavior. Never mind, what do we usually do when we sell things?

1. You're going to get a piece of paper with this table on it at first. (This corresponds to "dictionary")

|Fruit name|Number of times available for sale|Unit price|
|-----|--------------|---|
| Ship |2 | 1000|
|Grapefruit |1 | 2000|
|Melon |1 |8000 |
|Gam |6 |800|

That's all you know. Now you have to wait for the customer. Oh! That's so scary.

2. Whenever a customer comes, he asks, "What fruit do you want to eat?" and waits for the customer's answer. Then the customer answers the fruit they want to eat, such as "melon" and "plum." Oh! You're so rude to talk informally to me when you meet. (This corresponds to Save Input Variables)

3. Find out if the fruit name you heard as an answer is under "fruit name". If you don't have a name at all, or if the number of "available times" next to it is 0, answer "(fruit name) is not ready." (here 'pre-content search' occurs, and the value "inventory" in the problem seems to be intended to be "number of sales" no matter how much you read.)

4. If the name of the fruit you heard as an answer is in the table, and the "number of available sales" next to it is greater than 0, say "(fruit name) enjoy it," and then just calculate how much you need to get at least to sell the fruit. Oops! You have to sell at least 5 pieces, so you can multiply the price by 5 and let me know. (where basic operations and result output are required)

5. Take a pen, find the number of times you can sell the fruit in the table, and rewrite it to a number minus 1. (This corresponds to Save data correction, and the problem is, "If there are less than five, buy them," but I ignore this because I don't know what to do.)

If you've learned Python basics, you'll think, "Oh, what should I do with Python?" If you don't, you didn't learn Python.

I can do it. Try it.


2022-09-22 18:07

If you don't get it...

I don't think you understood Python's dictionary and user input processing.

Programming is...You see a lot, make a lot of mistakes, and improve when you make what you want to make...

The first person who answered well~

I think you can look at that and implement the code.


2022-09-22 18:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.