Question

Python code Write a complete program with for loop which calculates the sum of the numbers...

Python code

Write a complete program with for loop which calculates the sum of the numbers from 1 to 100

Homework Answers

Answer #1

# create main function
def main():
    # set total to 0 first
    total = 0
    for i in range(1, 101):  # make a loop to go from 1 to 100 (101 is exclusive in range here)
        total += i  # add that number to total
    print("Sum of the numbers from 1 to 100 is", total)  # finally print the total


# call the main function here
main()



Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Python program which calculates the average of the numbers entered by the user through...
Write a Python program which calculates the average of the numbers entered by the user through the keyboard. Use an interactive loop and ask the user at each iteration if he/she wants to enter more numbers. At the end dispay the average on the screen. Using built-in library functions for finding average is not allowed. Sample output of the program: Enter a number > 23 More numbers (yes or no)? y Enter a number > 4 Do you have more...
Write a python code that calculates the mean and median of a sample of 100 uniform...
Write a python code that calculates the mean and median of a sample of 100 uniform random numbers between 0 and 2 and the percentage of points in the sample that are greater than 1.
Write a Python program using while loop that finds and prints the sum of this geometric...
Write a Python program using while loop that finds and prints the sum of this geometric series. 1 + 2 +4 +8 + … + 1024
Write a program in MASM (32 bit) that calculates the sum of all odd numbers in...
Write a program in MASM (32 bit) that calculates the sum of all odd numbers in the Fibonacci sequence between 0 and 1,000,000. ***Please Complete in MASM 32 bit!!***
Write python code that reads a string with numbers and letters and outputs sum of the...
Write python code that reads a string with numbers and letters and outputs sum of the numbers and number of letters.
Write a python program to find the sum of the first n natural numbers, where the...
Write a python program to find the sum of the first n natural numbers, where the value of n is provided by the user. What is the sum of the first 200 numbers? Write a program that finds the average of a series of numbers entered by the user. As in the previous problem, the program will first ask the user how many numbers there are. Note: the average should always be a float. What is the average of 10.2,...
- Write a python program which prints all the numbers between 1 and 100 that are...
- Write a python program which prints all the numbers between 1 and 100 that are divisible by 3.
In python (use loop, if, else...) a)Enter a function that calculates the maximum common divider of...
In python (use loop, if, else...) a)Enter a function that calculates the maximum common divider of 2 numbers. b)Write a function that asks for time in seconds and converts it into hours, minutes, and seconds
Write a Python program to find the sum of the binary numbers in list L, where...
Write a Python program to find the sum of the binary numbers in list L, where the binary numbers do not have the quote marks necessary for the int() function. For example, if L = [101, 11, 1010] then the sum is 5 + 3 + 10 = 18. What is the sum when L is L = [10100, 101000, 100000, 1011111, 1000, 1010111, 1010010, 11001, 101100, 10111, 11011, 1011010, 11101, 10, 110011, 1001111, 110010, 101100, 100001, 111001]
Python: Write a program that makes sum of 1, 2, 3, … until the sum is...
Python: Write a program that makes sum of 1, 2, 3, … until the sum is over 1000.