0

so my program's aim is to compute the square of the difference of each parameter and the mean of the parameters. This code snippet runs perfectly with the correct resutls, but I want my program receives user inputs instead of inserting the arguments manualy.

Thank you in advance for your help

P.S.1 Yes, the program should have no limitations at the number of arguments that receives, as it seems

P.S.2 "Dwse arithmo" is the greek phrase for "Give a number" but with latin characters

import statistics as st
def squares(*args):
    for i in args:
        s=(i-st.mean(args))**2
        yield s
while True:
    x=input("Dwse arithmo")
for r in squares(3,4,5):
    print(r)
Marcel
  • 365
  • 2
  • 7
  • For future reference, you shouldn't show parts of your code that aren't relevant. Your question has nothing to do with the function. You are literally asking "how do I get a list of numbers from the user?" What you do with that list doesn't matter, especially if it's already working. Thinking modularly like that will help you solve problems and to formulate better search queries when you can't. – Mad Physicist May 10 '20 at 17:05
  • The problem goes beyond how to get the input and goes into how to feed the accumulated input (since you're prompting the user in a loop at runtime) back to your function. I think storing it in a list is going to be easier than trying to use a generator. – Samwise May 10 '20 at 17:10
  • `from statistics import mean; from typing import List; def squares(args: List[int]) -> List[int]:; return [(i - mean(args))**2 for i in args]; inputs: List[int] = []; while True:; inputs.append(int(input("Dwse arithmo: "))); print(squares(inputs)); ` – Samwise May 10 '20 at 17:11

0 Answers0