Python Forum
I need to add consecutive numbers help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need to add consecutive numbers help
#1
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
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Consecutive characters vijju56 4 4,899 Apr-22-2020, 11:03 AM
Last Post: TomToad
  Assign the sum of 2 consecutive numbers in a list to a varibale Fenaz 3 2,055 Apr-05-2020, 10:30 PM
Last Post: bowlofred
  creating consecutive rows PyPy 1 1,467 Feb-07-2020, 06:46 PM
Last Post: micseydel
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,667 May-09-2019, 12:19 PM
Last Post: Pleiades

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020