[Python] What is the function for Varied amount input data for Python?

Discussão em 'Python' iniciado por Stack, Outubro 23, 2024.

  1. Stack

    Stack Membro Participativo

    Statistics are often calculated with varying amounts of input data. Write a program that takes any number of integers as input, and outputs the average and max.

    Ex: If the input is:

    15 20 0 5 the output is:

    10 20

    nums = []

    # initialse
    number = 0
    # loop until there isn't an input
    while number != "":
    # ask for user input
    number = input('Enter number:')
    # validate the input isn't blank
    # prevents errors
    if number != "":
    # make input integer and add it to list
    nums.append(int(number))

    avg = sum(nums) / len(nums)
    print(max(nums), avg)


    All is gives me is Enter number:

    Continue reading...

Compartilhe esta Página