13 Answers
New AnswerI can't enter the input values for simple interest program.It will be helpful for me if you answer to this question.
2/3/2020 12:47:46 AM
FOCUS Calligrapher13 Answers
New AnswerIf you instruct the user to enter the numbers separated by spaces, this is all you need: lst = [int(n) for n in input().split()] print("average =", sum(lst)/len(lst))
In your code, you wrote these lines: lst=int(input("ENTER A LIST:\n")) n=list(lst) This doesn't work, because the int function will not be able to read a string with several numbers (like 5 8 2 5 1) as *one* int. First, you would have to split the string. lst=input("ENTER A LIST:\n").split() Now it is already a list of the inputs, split by white space (7 5 3 becomes ['7', '5', '3']). Now you have a list of number string, on which you can, for example in a loop, apply int().
On SL code playground, if you want to enter multiple inputs, you need to separate them with newlines as well.
To get multiple inputs you can use this bit:: str=input(" ").split(' ') var=[int(num) for num in str] This code will store all input seperated by "space" into var array. And you can retrieve individual values using for and while loop.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message