Write a menu driven program in python that allows a user to create a list
Answers
Is it English.
Plz search in book.
This time they added python in English also?
To do this, first we will ask the user whether they actually want to create a list or not.
yes_no = input('Do you want to create a list?[y/n]')
Now that we have an input, we will have two conditionals, first, if the yes_no is 'y' and second, it the yes_no is 'n.'
If it is y, then ofcourse, we create a list and add the elements in the list according to the user.
Here is how you do it.
CODE:
yes_no = input('Do you want to create a list[y/n]')
user_list = []
if yes_no == 'y':
num = int(input('How many elements do you want to add in this list?'))
for i in range(num):
elem ent= input(f'Enter your element({i})')
user_list.append(element)
print(f'Here is you list: {user_list}')
else:
print('Ok, make your list next time! :)')
break
__________________________________________
This is how it works. First, we would be asked if we want to create a list. Then, I created an empty list where I can add all the inputs from the user. Next, we ask the user how many elements does he/she would like to append. We take the range for that specific number because the element input runs for the number of times the user wants to add elements to list and at last, we print out the list, saying Here is your list:
___________________________________________
We can all types in this list, be it float, integer, string, bool, None