Feijó Posted February 28, 2014 at 02:12 AM Report #547027 Posted February 28, 2014 at 02:12 AM (edited) Boas ando a aprender python, e encontrei um site com desafios. e estou com dificuldades neste: When I start to feed my pigeon, a minute later two more fly by. And a minute later another 3. Then 4, and so on. One portion of food lasts a pigeon for a minute. In case there's not enough food for all the birds, the pigeons that came first, eat first. Pigeons are hungry animals and eat without stopping. If I have N portions of wheat, how many pigeons will be fed with at least one portion of wheat? e deveria dar este resultado: checkio(1) == 1 checkio(2) == 1 checkio(5) == 3 checkio(10) == 6 isto foi o código a que cheguei: def checkio(number): minu=0 birds=0 while number>0: minu=minu+1 birds=birds+minu number=number-birds return birds obrigado- Edited February 28, 2014 at 02:12 AM by Feijó
Olos Posted March 1, 2014 at 12:10 AM Report #547207 Posted March 1, 2014 at 12:10 AM (edited) Boas. Um problema com a função é que está a retornar o número total de pombos e não quantos é que efectivamente comeram. Edited March 1, 2014 at 01:15 AM by Olos
thoga31 Posted March 1, 2014 at 12:48 AM Report #547208 Posted March 1, 2014 at 12:48 AM Não é suposto darmos a solução mas sim ajudar os membros a encontrarem-na por si. Knowledge is free!
Feijó Posted March 1, 2014 at 04:25 PM Author Report #547233 Posted March 1, 2014 at 04:25 PM Boas. Um problema com a função é que está a retornar o número total de pombos e não quantos é que efectivamente comeram. Obrigado 🙂 sempre consegui fazer o exercício, se tiverem alguma crítica que me ajude a melhorar agradecia 🙂 foi a esta resposta que cheguei : def checkio(number): minutos=0 birdsA=0 birdsF=0 while number > 0: minutos=minutos+1 birdsA=birdsA+minutos if birdsA<=number: birdsF=birdsA number=number-birdsF elif number>birdsF: birdsF=number else: break return birdsF
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now