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.
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.
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")
...
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