Can you please help me? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can you please help me?

the task requires the user to input a list of numbers with a terminating number 0 then it will print the number of input excluding 0 and that is count also it will print the sum of the numbers lastly print the mean of those numbers https://code.sololearn.com/c193uR5p108R/?ref=app

30th Mar 2023, 2:23 PM
Erika Abalora
15 Answers
1st Apr 2023, 7:55 AM
JaScript
JaScript - avatar
+ 10
1. I do not understand why you need: • 2 while loops • eval() function • nested if-statements 2. What I would suggest: • Rather than asking for each number separately, you can input a list of numbers separated by comma, such that: 1,2,3,4,5 • Split the input received by comma to make a list • Convert items in a list into an integer, e.g. "3" -> 3 • Use built-in functions such as len() & sum() to get functionality you want • Do not use built-in functions as variable names. 3. To improve, you can: • Add validation that will check/restrict some input entered by the user, e.g. entering text rather than numbers • Add some code that will catch exceptions such as: TypeError, ZeroDivisionError For your information; there is a built-in python math module, which already has this functionality, however try to do it yourself to solidify your skills in python.
30th Mar 2023, 2:55 PM
Lamron
Lamron - avatar
+ 9
Ela , the task description is a bit weak, so we need to know: > what is the first number for? does it define how many numbers should be input? let's assume we wanted to get 5 numbers taken by ths input function. where do you store these numbers for the requested calculations?
30th Mar 2023, 3:51 PM
Lothar
Lothar - avatar
+ 5
The task is not clear for me too. I think this code will help you: https://code.sololearn.com/c0xN23ffvRki/?ref=app
30th Mar 2023, 6:03 PM
JaScript
JaScript - avatar
+ 5
Lamron Please note that the collection of numbers ends with the input of the number zero. For example as presented input example at the beginning of this code and I think like Ela wanted: 2 4 0
30th Mar 2023, 7:01 PM
JaScript
JaScript - avatar
+ 4
Can you show us your solution?
1st Apr 2023, 8:01 AM
JaScript
JaScript - avatar
+ 3
Ela I can see what you are trying to do with your code and I think others have covered alternatives to how to.get the answer. I'm new to coding, but for me I read your code not defining the variable of sum and so hence it would not work, also other variables declared but unnecessary as not used at those steps. If I was you I would break the code into smaller steps and check each step works in principle the combine it together. It looks like you tried to do that but seems to have lost checks on continuity. Well done on trying this, I know for myself it is easy to get lost in the code steps and bot knowing what functions can help. I use chatGPT for advice on what alternatives could work or where my code has gone wrong when I get stuck trying to create something new. It works well as a second pair of eyes to draw my attention to where I've gone wrong or how another library function could simplify my code.
31st Mar 2023, 9:34 AM
Rob Newman
Rob Newman - avatar
+ 3
You are welcome Ela
1st Apr 2023, 8:27 AM
JaScript
JaScript - avatar
+ 2
Kunal Sankliya , I suggest you start a new post with a short title of what you need help with and include a short description of what it is you have a problem with. That way the many helpful people of the Sololearn community can give their helpful advice. In early stages of sololearn lessons there is good step by step summary and the comments section usually gives lots of extra help too.
31st Mar 2023, 7:22 PM
Rob Newman
Rob Newman - avatar
+ 2
I was going to suggest a while true logic would be better suited like JaScript suggested. Get aroud the eof error that way. Is that the solution you used Ela ?
1st Apr 2023, 8:36 AM
Rob Newman
Rob Newman - avatar
+ 1
JaScript EOFError line 12
30th Mar 2023, 6:49 PM
Lamron
Lamron - avatar
+ 1
I solved it
1st Apr 2023, 7:49 AM
Erika Abalora
+ 1
yes thankyouuu JaScript
1st Apr 2023, 8:12 AM
Erika Abalora
0
Help mi
31st Mar 2023, 6:32 PM
Kunal Sankliya
Kunal Sankliya - avatar
0
I edited the question
1st Apr 2023, 7:30 AM
Erika Abalora