H
H
h4ckurman2021-06-29 21:20:27
Python
h4ckurman, 2021-06-29 21:20:27

Can you check if my solution is correct?

Hello!
I'm reading Tony Gadis' book Getting Started with Python 4th Edition and programming myself.

60db64bf09f6c963988153.png
I seem to have solved this problem myself, but I want you to check it and suggest more alternative solutions (only in a "newbie" way, I don't understand the intricate code :D )
Here is my code, please don't judge strictly:

# входные данные
peoples = int(input('Количество участников пикника? '))
hot_dogs = int(input('Количество хот-догов, которые будут предложены каждому участнику: '))

SAUSAGES = 10
BUNS = 8
number_of_hot_dogs = peoples * hot_dogs # количество хот-догов всего
print('Всего количество хот-догов:',number_of_hot_dogs)
number_of_sausage = number_of_hot_dogs // SAUSAGES # вычисление количества пакетов сосисок
print('Количество пакетов с сосиcками, которые понадобятся:',number_of_sausage)
number_of_bun = number_of_hot_dogs // BUNS # вычисление количества пакетов булок
print('Количество пакетов с булками, которые понадобятся:',number_of_bun)

# оставшееся количество сосисок и булок
remaining_of_sausages = number_of_hot_dogs % SAUSAGES
remaining_of_bun = number_of_hot_dogs % BUNS
print('Количество оставшихся сосисок:',remaining_of_sausages)
print('Количество оставшихся булок:',remaining_of_bun)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-06-29
@h4ckurman

number_of_sausage = number_of_hot_dogs // SAUSAGES
Obviously wrong. Try 25 hot dogs to order, get 2 packages of sausages, but 2 packages only have 20 sausages. It's the same with buns.
The calculation of the remainder, respectively, is also incorrect. At 25 hot dogs, you'll end up with 5 sausages leftover, even though you haven't even made it to the total number of people. If you specify the number of people as 1, the number of hot dogs is also 1, then we get 1 sausage and 1 bun in the remainder, although we bought 10 sausages and 8 buns
. In the first case, refine the division, try to transfer such values ​​so that the total number of hot dogs is not a round number.
In the second division, in principle, it is not necessary, you need to subtract the number of purchased products from the number of spent
The task is easy, you can do it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question