Помогите решить задачу | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Помогите решить задачу

Давайте представим, что вы хотите купить мороженое 10 друзьям. Напишите программу, которая возьмет имеющиеся у вас деньги и цену одного мороженого и выведет оставшиеся деньги только в том случае, если вы можете купить мороженое для всех 10 своих друзей. Пример ввода 80 7 Пример вывода 10 Объяснение 7*10 = 70. 10 — это оставшаяся сумма (80-70).

16th Sep 2020, 5:30 AM
Alex Burdik
Alex Burdik - avatar
11 Answers
+ 4
It's very simple. Please try to do it yourself before asking. You'll learn only if you try to code. Hint: If you divide available money by the price of one ice-cream you get the number of ice-creams that you can buy. If number is equal or greater than 10 all your friends will get ice-cream. Now try to code it yourself. If you get some errors post your code here. We'll try to help you but you need to make some efforts first.
16th Sep 2020, 6:02 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 4
money = int(input()) price = int(input()) stoimost = price*10 if money <= money + price: if money >= stoimost : ost = money % stoimost print (ost) # место для вашего кода
18th Oct 2020, 9:55 PM
Sergio Kiryushkin
Sergio Kiryushkin - avatar
+ 3
Вопрос, почему это принимается? :) money = int(input()) price = int(input()) if money >= price *10: print (money -(price *10))
6th Nov 2020, 1:32 PM
Максим
+ 2
Не мог решить, как решил полез сравнить в ответы, скажите, зачем вы все усложняете? Вот верный и простой ответ: money = int(input()) price = int(input()) sum = price * 10 if sum <= money: print (money - sum) Оптимизируйте код, иначе будут тормоза!
1st Nov 2021, 9:11 AM
Никита Барков
Никита Барков - avatar
+ 1
Здравствуйте! Sololearn — это общество, где мы помогаем друг другу учиться, а не пишем друг за друга код. Напишите свой вариант решения в code playground-е, и если что-то не получится, задавайте вопрос здесь, указав ссылку на свой код. Удачи в учёбе!
16th Sep 2020, 6:03 AM
Tato
Tato - avatar
+ 1
money = int(input()) price = int(input()) friends = 10 summa_ice = price * 10 ostatok = money % summa_ice if ostatok >= 0: print(ostatok)
16th Sep 2020, 6:52 AM
Alex Burdik
Alex Burdik - avatar
0
Translation : Help solve the problem Let's say you want to buy ice cream for 10 friends. Write a program that will take the money you have and the price of one ice cream and only withdraw the remaining money if you can buy ice cream for all 10 of your friends. Input example 80 7 Output example ten Explanation 7 * 10 = 70.10 is the remaining amount (80-70).
16th Sep 2020, 5:56 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
0
Вот выдает ошибку из 5 тестов только во втором
16th Sep 2020, 6:52 AM
Alex Burdik
Alex Burdik - avatar
0
Alex Burdik , Well tried 🙂! There is a minor mistake. Think about this scenario- The amount of money that you have is actually less than what is required. let's say, you have 70 units. each ice-cream costs you 10 units. Total money required = summa _ice = 10*10 = 100 and in your code when you do : money % summa_ice 70 % 100 it gives you 70. You see what's wrong? Whenever you modulo divide n by a number m where m>n you get n. To fix this: if summa_ice <= money: print(ostatok) This first checks if you have enough money. If you do then only it prints remainder (ostatok)
16th Sep 2020, 9:52 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
0
money = int(input()) price = int(input()) friends = 10 summa_ice = price * 10 ostatok = money % summa_ice if ostatok >= 0 and ostatok <= 100: print(ostatok)
19th Nov 2020, 1:35 PM
Skywalker
Skywalker - avatar
- 2
Подскажите, пожалуйста, почему не принимается такое решение? money = int(input()) price = int(input()) if money <=100: if money >= price *10: print (money %(price *10))
2nd Nov 2020, 10:07 AM
Andrew