User input giving me different output in equation. Python. | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

User input giving me different output in equation. Python.

This is for the duct tape coach problem. The output changes if the input is separated by spaces or a new line. If the user inputs "4 7" the output is 6. If the user inputs: "4 7" The output is 15. The only difference is the user pressing return and a new line forming in the input list. How do I code it so that both inputs appear on the same line matter how it is entered? I'm trying to shy away from using a loop. https://code.sololearn.com/c7BWO3KS7ZO4/?ref=app import math l=list(map(int,input().split())) new_list = [i * 12 for i in l] area = sum(new_list) print(math.ceil(1440/(area*2)))

2nd May 2020, 11:30 AM
Ilya Khleboyko
Ilya Khleboyko - avatar
4 Respuestas
+ 1
I see what your trying to do, and I've never been able to do it. My fix is to always add a string in the input and it acts as a prompt specifier. Inside input, I'd put: 'Enter two numbers sperated by a space > ' if thats what you wanted. The other way is to have a try and except set up. If information is entered the wrong way, raise an error and have a string tell them how to enter it correctly and redirect them back to the prompt
2nd May 2020, 1:36 PM
Slick
Slick - avatar
+ 1
Ahhh i didnt know your problem was just on here. Sorry friend, on sololearn input can only be handled one way. And its by taking all input at once. It should work in cmd or terminal or an IDE though
2nd May 2020, 2:41 PM
Slick
Slick - avatar
0
Sounds easy, but I can't tell the code coach to input the code correctly.
2nd May 2020, 2:26 PM
Ilya Khleboyko
Ilya Khleboyko - avatar
0
Hey! Why does the task say that tape is 60 feet long, cause it shuld be 60 inches long instead? Because we devide 60 by 12 in the right code
13th Jun 2023, 7:00 PM
Alexander Glyantsev