+ 1

Ticket solution not working

Does anyone know why this code isn’t working? I have checked the solution and made sure they match, but it always gives an error for line 4 https://code.sololearn.com/c1NMbOuNoz6O/?ref=app

23rd Jun 2022, 6:17 PM
Ben Rogers
20 Respuestas
+ 3
Check your indentation. It looks like your x+=1 is not part of the while loop
23rd Jun 2022, 6:22 PM
John Doe
+ 1
Justice you can, but it has to be provided when running the program (on separate lines)
23rd Jun 2022, 6:24 PM
John Doe
+ 1
Justice I read what you said. I think you need to read my comment again
24th Jun 2022, 4:09 PM
John Doe
+ 1
total = 0 x = 1 age=0 while x<= 5: age = int(input()) if age >=3: total +=100 x+=1 print(total)
25th Jun 2022, 1:49 AM
Dineshkumar R
Dineshkumar R - avatar
+ 1
Ben Rogers.....you have intialize the age....
25th Jun 2022, 1:51 AM
Dineshkumar R
Dineshkumar R - avatar
0
You cannot ask for input within a loop on Sololearn. If you need to ask for input, ask them all at the same time. An attempt to ask for more information will result in an error due to SL not being a proper IDE.
23rd Jun 2022, 6:21 PM
Justice
Justice - avatar
0
So i tried moving the input out, but this results in no output which makes sence, i can try the indentation but the erroe i keep getting says line 4 is the issue
23rd Jun 2022, 6:27 PM
Ben Rogers
0
John Doe Please read what I said carefully. I said it is possible if they ask at the SAME time. //I was wrong A loop is not the same item because a loop is iterable. So they would like input for each iteration of the loop, which unfortunately is not possible on Sololearn specifically. You're on allowed to give input one. I didn't say they could give multiple inputs, but they have to ask for it at the same time. Multiple Inputs at the same time ✅ Asking for input multiple/different times ❌
23rd Jun 2022, 6:28 PM
Justice
Justice - avatar
0
So as sololearn is doing the input for the test, how do i get around this?
23rd Jun 2022, 6:33 PM
Ben Rogers
0
Ben Rogers Can you post the task description so we know what the expectations are?
23rd Jun 2022, 6:35 PM
Justice
Justice - avatar
0
Sure. One min
23rd Jun 2022, 6:35 PM
Ben Rogers
0
You are making a ticketing system. The price of a single ticket is $100. For children under 3 years of age, the ticket is free. Your program needs to take the ages of 5 passengers as input and output the total price for their tickets. Sample Input 18 24 2 5 42 Sample Output 400
23rd Jun 2022, 6:36 PM
Ben Rogers
0
I looked online and i can do it using a for loop, but i want to understand how to fix it with a while loop
23rd Jun 2022, 6:37 PM
Ben Rogers
0
Traceback (most recent call last): File "file0.py", line 4, in <module> age = int(input()) EOFError: EOF when reading a line This is the error i get
23rd Jun 2022, 6:40 PM
Ben Rogers
0
Ben Rogers I see. What you can do is ask for the input all at the same time like I stated before into 5 different variables before the loop. Then you can check each variable and see if it is over the age to add the 100. I would add them to a list and iterate over the list but I'm not sure if you've gotten to that lesson yet.
23rd Jun 2022, 6:40 PM
Justice
Justice - avatar
0
Nope not that far yet!🤦‍♂️ first day 😂
23rd Jun 2022, 6:41 PM
Ben Rogers
0
That's alright! So just check each variable individually. If the variable is over 3, then add to the amount. You can use the tools from the lesson that you're on. They try to make the project connect to the keywords you learned in that same lesson.
23rd Jun 2022, 6:43 PM
Justice
Justice - avatar
0
Here's the thing. What John and Justice say are both true. 1) You can indent your x += 1 back in under the while loop and then run the code. What you do is provide an input and press enter until all inputs are given. This gives all input at the same time. (if num of inputs is finite and known) When you have an IDE with a comment/uncomment feature, and all you need is a final output, you can do this: (using tickets example) type 2 5 9 2 6 you can select them and the empty line below, copy them, then comment them all at once using your IDE, and paste it all in your terminal to have your output. The new lines in your copied content do your thing for you. Anytime you need to run it, uncomment, copy, comment, paste. 2) If you need to have an output after each input, that is what you cannot do on SL. e. g Guess the integer - from 0 to 100 (borrowing Don't Know's game) input : 50 output: too large in : 25 out: too small in: 37 and so on, where input depends on output, SL doesn't do that
23rd Jun 2022, 11:27 PM
Korkunç el Gato
Korkunç el Gato - avatar
0
John Doe I see what you mean now. Though, I still don't understand how that would be possible with a program where you can't know what the should be after a particular iteration. Like for example with a program that runs Hangman, or a even a program that has many more lines of code and iterables.
24th Jun 2022, 4:14 PM
Justice
Justice - avatar
0
I figured out why it wasnt working, i originally had x=0 at the top (which means i would need 6 input) so when i changed it to x=1 it worked for 5 inputs which was the task
25th Jun 2022, 5:06 AM
Ben Rogers