Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to take in both input split by space(s) and by line(s)

for example I have this 2 inputs:

2 5 2

and:

2
5
2

How do I take all of them using the same code?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Read lines of input and split them until you get 3 total values.

inputs = []
while len(inputs) < 3:
    values = input().split()
    inputs.extend(values)

print(inputs) # this will print [2, 5, 2]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading