'already have my loop but idk how to extract the inputs from my loop to use in a another function : (

I don't really have any problems but the things is I need to validate the inputs and I don't know how to extract the validated inputs to calc_average()

please help on how to extract integer inputs for functions to use



Solution 1:[1]

have you tried storing the validated inputs into a list? Then you can pass that list into your function.

For example

create_list = []

# Block of code where you are validating your input
  # You know input is valid, so now
    # Add that input into your create_list list

Then you pass create_list to your calc_average function where you need to implement the function such that it can work with a lists.

Hope this was helpful, best of luck.

Solution 2:[2]

I think code below is what you need and I suppose you know how to calculate average:

is_valid = False
inputs = []

while not is_valid:
    # here you will give input like this(use spaces in between): 1 2 3 4
    inputs = list(map(int, input().rstrip().split()))
    is_valid = all([0 <= int(mark) for mark in inputs])

calc_average(inputs)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kashfi
Solution 2 iliya