Computer Science, asked by kirtibhansingh7, 21 days ago

write the program in python to print the sum of 5 numbers​

Answers

Answered by sanjudnath
5

Answer:

See this example:

num = int(input("Enter a number: "))

if num < 0:

print("Enter a positive number")

else:

sum = 0.

# use while loop to iterate un till zero.

while(num > 0):

sum += num.

Answered by kumark54321
0

Answer:

The following Python program will print the sum of 5 numbers:

Explanation:

We can use a loop to take 5 numbers as input from the user, and add them to a variable called "sum".

After the loop, we can print the value of "sum" to get the final sum of the 5 numbers.

Here is the program in pointwise format:

Initialize a variable called "sum" to 0.

Use a loop to take 5 numbers as input from the user:

a. Inside the loop, use the input() function to take a number as input and convert it to an integer using the int() function.

b. Add the input number to the "sum" variable.

After the loop, print the value of "sum" using the print() function.

The complete Python program to print the sum of 5 numbers is as follows:

sum = 0

for i in range(5):

   num = int(input("Enter a number: "))

   sum += num

print("The sum is:", sum)

Keywords: Python, program, print, sum, loop, input, integer, variable.

Learn more about Python programming from the given link:

https://brainly.in/question/16086632#:~:text=Expert%2DVerified%20Answer&text=Salient%20features%20of%20Python%20Programming,and%20provides%20dynamic%20type%20checking.

Learn more about Print from the given link:

https://brainly.in/question/48856987#:~:text=Expert%2DVerified%20Answer&text=The%20correct%20answer%20is%20Print,the%20page%20for%20final%20printout.

Learn more about variable from the given link:

https://brainly.in/question/3016346

Learn more about loop from the given link:

https://brainly.in/question/14646776#:~:text=Expert%2Dverified%20answer&text=In%20computer%20science%2C%20a%20loop,a%20specific%20condition%20is%20met.&text=In%20Java%20Script%20there%20are,different%20values%20is%20called%20Loops.

Learn more about Input from the given link:

https://brainly.in/question/9805321

Learn more about Integer from the given link:

https://brainly.in/question/54141444

Similar questions