+ 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.

3rd Feb 2020, 12:47 AM
FOCUS Calligrapher
FOCUS Calligrapher - avatar
13 Respuestas
+ 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))
3rd Feb 2020, 9:24 AM
David Ashton
David Ashton - avatar
+ 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().
3rd Feb 2020, 1:04 AM
HonFu
HonFu - avatar
+ 4
Can you show us the problematic piece of code?
3rd Feb 2020, 12:50 AM
HonFu
HonFu - avatar
+ 4
On SL code playground, if you want to enter multiple inputs, you need to separate them with newlines as well.
3rd Feb 2020, 1:10 AM
Sonic
Sonic - avatar
+ 3
Wrong link. ;)
3rd Feb 2020, 1:00 AM
HonFu
HonFu - avatar
+ 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.
4th Feb 2020, 2:29 PM
Bgg_cyber
Bgg_cyber - avatar
+ 2
Thank you
3rd Feb 2020, 1:08 AM
FOCUS Calligrapher
FOCUS Calligrapher - avatar
+ 1
Sorry
3rd Feb 2020, 1:02 AM
FOCUS Calligrapher
FOCUS Calligrapher - avatar
3rd Feb 2020, 1:02 AM
FOCUS Calligrapher
FOCUS Calligrapher - avatar
0
Interest=int(input("enter interest"))
4th Feb 2020, 3:47 PM
SHIVAM SHARMA
SHIVAM SHARMA - avatar
0
What?
4th Feb 2020, 9:33 PM
XaKer Na PiTOne
XaKer Na PiTOne - avatar
0
How to enter inputs for c++
25th Oct 2020, 4:43 PM
Ram Kumar
Ram Kumar - avatar