Answers for "use of flag in python"

1

use of flag in python

# First we will name the flag
num_entry = True # while it is true it will run
list1 = []  # An empty list
"""We will make one loop by using the flag and do the summation and will take
care that we don't press 0 as it will end the programme because the condition is
set to 0 if 0 is entered num_entry = False will be there"""
print("Press 0 anytime to add the numbers\n")
while num_entry:
  ask_user = int(input("Enter the Number: ")) # If entered 0 it will stop 
  list1.append(ask_user)
  if ask_user == 0:
    num_entry = False

# Now we will display the sum of the entered numbers
list_sum = sum(list1)
print(f"Sum of the Entered numbers is {list_sum}")
Posted by: Guest on October-26-2021

Python Answers by Framework

Browse Popular Code Answers by Language