Home > front end >  already have my loop but idk how to extract the inputs from my loop to use in a another function : (
already have my loop but idk how to extract the inputs from my loop to use in a another function : (

Time:03-27

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

CodePudding user response:

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.

CodePudding user response:

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)
  • Related