Python Forum

Full Version: I need to add consecutive numbers help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello
I have three numbers and I have to find minimum of them .k=min(a,b,c) No problem.
After I need to add all the numbers until k to the another certain value
Lets say k=5 so I need to add (1 2 3 4 5)
and check
if x+1>y:
do this
if x+2>y:
do this
if x+3>y:
do this
if x+4>y:
do this
if x+5>y:
do this

How can I do that ?
Thank you so much
Well, the problem is not clear at all. You've got a, b, and c, with the minimum being k, that's clear. Summing from 1 to k is easy, you just need the sum and range built-ins. But then where do x and y come from? You haven't defined them anywhere. And what if x is 1 and y is 1. Then all of the conditions you listed are true. Is the code supposed to do five things, or just one?

It would be good to clarify those points. Then it would be good to try to write some code to solve the problem yourself. We're not big on writing code for people here. We are big on helping people fix code they've written. Especially if they tell us exactly what is going wrong.