What's new

Python listing pa help

Oh No_

Forum Veteran
Elite
Joined
Sep 29, 2016
Posts
2,515
Reaction
780
Points
1,004
#Ito po code ko diko talaga ma gets. Pa help mga papsy
sum, i=0, 3
number=int(input("Input number:"))
choice = input("Again?(Y/N)")
while choice.lower() == "y" or choice.upper() == "Y":
for i in range(1,3):
sum = sum + number
print("Total number inputted:",choice)
print("Sum:",sum)


#Gusto koopo output is yung
>Total inputted number: #mag output kung kelan ilang beses ako nag input ng number
>Sum: #yung ma add sana number ng total na nainput ko.
 
Parang malayo answer mo sa gusto mo mangyari.

Python:
sum = 0
inputCounter = 0
choice = "y"

while choice.lower() == "y":
    sum = sum + int(input("Input number: "))
    inputCounter += 1
    choice = input("Again?(Y/N): ")
     
print("Total number inputted:", inputCounter)
print("Sum:", sum)

Pero kung iconsider na dapat nasa List ang input. Ganito yan

Python:
inputList = []
choice = "y"

while choice.lower() == "y":
    inputList.append(int(input("Input number: ")))
    choice = input("Again?(Y/N): ")
       
print("Total input:", len(inputList))
print("Sum:", sum(inputList))
 
Last edited:
Python:
# create an empty list to store the numbers entered by the user
numbers = []

# ask the user if they want to enter a number
try_again = input("Do you want to enter a number? (yes/no): ")

# keep asking for a number as long as the user wants to
while try_again.lower() == "yes":
  # ask the user for a number
  num = input("Enter a number: ")
  # add the number to the list
  numbers.append(num)
  # ask the user if they want to try again
  try_again = input("Do you want to enter another number? (yes/no): ")

# calculate the total number of numbers entered
total_numbers = len(numbers)

# calculate the sum of the numbers entered
sum_numbers = sum(numbers)

# print the total number of numbers entered
print("Total numbers: ", total_numbers)

# print the sum of the numbers entered
print("Sum of numbers: ", sum_numbers)
 

Similar threads

Back
Top