campusx-official / dsmp-2022-23

All the codes and tasks taught in the CampusX Data Science Mentorship Program 2022-23
7 stars 1 forks source link

Multiple Inputs in Single Line #7

Open samp-suman opened 1 year ago

samp-suman commented 1 year ago

We learned to take input from user, but only one input at a time. So, my question is how can I take multiple inputs in same line. Because I saw in competitive programming most of the questions need multiple inputs in same line. So, how can I code this?

samp-suman commented 1 year ago

In string you would have learned a method of string - split(), using this you can take multiple inputs from the user.

For example you want two numbers from user to do some operation-- this is how you will take input of two nos.

a, b = input("Enter two nos. space separated").split()
a=int(a)
b=int(b)

or other way of doing is

a, b = list(map(int, input("Enter two numbers space separated-").split()))

map() and list() function you will learn later in the course.