+ 3
How to enter the input values for a program?
I can't enter the input values for simple interest program.It will be helpful for me if you answer to this question.
13 Réponses
+ 7
If 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))
+ 5
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().
+ 4
Can you show us the problematic piece of code?
+ 4
On SL code playground, if you want to enter multiple inputs, you need to separate them with newlines as well.
+ 3
Wrong link. ;)
+ 3
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.
+ 2
Thank you
+ 1
Sorry
0
Interest=int(input("enter interest"))
0
What?
0
How to enter inputs for c++