PYTHON 3 BEGINNER . I have the design for this function, but I need help writing
ID: 3716244 • Letter: P
Question
PYTHON 3 BEGINNER . I have the design for this function, but I need help writing the rest of the code. Here's what I have:
#------------------------------------------------------------pick_from
# Purpose: present a list of choices to the user, validate answer and return it
# Preconditions: list of choices
# Postconditions: returns integer which is position of choice in the list
# if list is empty, just say nothing here and return -1
# otherwise
# display list with numbers from 1 to length of list
# ask user for choice
# using while loop, check for valid number
# inside, tell user that it is bad, ask again
# return integer (subtract one so it is the correct subscript in the list)
Explanation / Answer
Please check below the sample code for your given requirement :
list1=["A","B","C","D"]
list2=["E","F","G","H"]
list3=["I","J","K","L"]
print(list1)
print(list2)
print(list3)
choise = input("Please chose the list ,enter 1 for 1st list , 2 for 2nd and 3 for 3rd list :" )
while(true)
if(choise >=1 and choise <=3)
if(choise==1)
print(list1)
break
elif(choise==2)
print(list2)
break
else(choise==3)
print(list3)
break
else
print("It is bad input, Please try again")
choise=input("try again" :)
Add as many list as you want to add and change the code accordingly.
Thanks you :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.