In: Computer Science
1.write a small program using a loop to add a series of numbers
2.write a function called "main" that performs several given steps. Be sure to call the main() function so that its code executes
In python and doesn't have to be long. just long enough to do what it says. Thank you.
1) the code to add series of numbers is :
for num in range(0, number+1):
sum += num
considering the "number" is already given and sum is also assigned to zero
2) the code to make function called "main()" and perform the
above operation is:
def main():
number = int(input("Enter any number: "))
sum = 0 # it will hold the sum
# for is use to loop from zero to given number
for num in range(0, number+1):
sum += num
print("The sum from zero to", number, "is", sum, end="")
The above fucntion will take input from the user and add a series of number and print them
Please refer to the screenshot of the code to understand the indentation of the code.
Output:
Hope this helps you. If you have any doubt ask in the comments section. Thank you