-3

For example

print("Which Of the Following Activities Do you Enjoy?")
print("1)Swimming\n2)Jogging\n3)Basketball\4)Football\n5)Yoga")

I would like the user to input their choices like 1,2 or 3,4,5 etc. i.e get variable no of inputs from the user.

gio
  • 4,950
  • 3
  • 32
  • 46
S.S
  • 11
  • 2
  • Does this question actually looks like you had in mind? If not, please read [How do I format my posts using Markdown or HTML?](http://stackoverflow.com/help/formatting) (You may also be interested in reading [how to ask a good question](http://stackoverflow.com/help/how-to-ask).) – Jongware Feb 12 '16 at 11:45
  • Possible duplicate of [How can I read inputs as integers in Python?](http://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-integers-in-python) – Lafexlos Feb 12 '16 at 11:46

2 Answers2

0

One way is, you can get the input from the user as a string and use split(',') to get the array of all the user's choices.

str = input('')
str = str.split(',')
for choice in str:
    if choice == "1":
        print("Swimming")
    ...
0

Pythons raw_input() returns a string, but you can split this string to get a list, using the raw_input().split()

So in your case you can do the following.

print("Which Of the Following Activities Do you Enjoy?")
print("1)Swimming\n"
      "2)Jogging\n"
      "3)Basketball\n"
      "4)Football\n"
      "5)Yoga")

user_choice = raw_input().split(' ,')

and then you can iterate through user_choice and get the individual choices.

for choice in user_choice:
    # do what you want
cyberbemon
  • 3,000
  • 11
  • 37
  • 62
  • You should split on spaces as well, to be more user friendly. str.split can take multiple separator characters, like this: `raw_input().split(' ,')` – Håken Lid Feb 12 '16 at 12:05