0

How to make a program "sum of consecutive number" in python

14th Jan 2023, 3:40 PM
Bidur Pokhrel
Bidur Pokhrel - avatar
8 Respostas
+ 5
Bidur Pokhrel There is no point of others coding stuff for you, if you do not understand it and learn it yourself. Read the lessons again, as Lisa said, and try to implement into practice what you know. You have to try, and not wait for others to code for you :)
14th Jan 2023, 4:11 PM
Lamron
Lamron - avatar
+ 4
How often are you going to post the same question?
14th Jan 2023, 3:41 PM
Ausgrindtube
Ausgrindtube - avatar
+ 3
Take a break, then write the code. Then: Show the code so we can check on it and make suggestions. I have described the approach to you in your thread with the same question and that you deleted.
14th Jan 2023, 5:01 PM
Lisa
Lisa - avatar
+ 2
If you are fustrated then you must have something to show? Please share your attempts so that we can see where you may have gone wrong.
15th Jan 2023, 7:29 AM
Chris Coder
Chris Coder - avatar
+ 2
Bidur Pokhrel I just noticed that you recently joined sololearn only 3 days ago. Welcome to Sololearn. We are a learning platform, Here we don't simply provide answers to home work. But if you provide your atttemp we are more than happy to help you with programming related questions. Get started with the basic python fundamentals. If you don't know python already. If you do know python it wont hurt to revise. https://www.sololearn.com/Course/Python-for-Beginners/?ref=app I have already worked up a solution to the code with some explinations. I'm just waiting for you to show that you have a basic understanding of the fundamentals of python. https://www.sololearn.com/Discuss/3021159/?ref=app https://code.sololearn.com/W1AxdV4e2H68/?ref=app Updated Guideliness: https://www.sololearn.com/Content-Creation-Guidelines/
15th Jan 2023, 8:21 PM
Chris Coder
Chris Coder - avatar
0
Please code this for me. I am being frustrated.
14th Jan 2023, 3:42 PM
Bidur Pokhrel
Bidur Pokhrel - avatar
0
You can create a program in Python to find the sum of consecutive numbers using a for loop. Python Code : # Take input from the user num = int(input("Enter the number of consecutive integers to add: ")) # Initialize the sum sum = 0 # Use a for loop to iterate through the range of integers for i in range(1, num+1): sum += i # Print the sum print("The sum of the first", num, "consecutive integers is:", sum)
16th Jan 2023, 2:33 PM
Shah Fahad
Shah Fahad - avatar
0
You can also use a while loop to achieve the same result: Python Code : # Take input from the user num = int(input("Enter the number of consecutive integers to add: ")) # Initialize the sum sum = 0 # Initialize the counter i = 1 # Use a while loop while i <= num: sum += i i += 1 # Print the sum print("The sum of the first", num, "consecutive integers is:", sum)
16th Jan 2023, 2:34 PM
Shah Fahad
Shah Fahad - avatar