Jul-06-2018, 10:20 PM
(Jul-06-2018, 12:58 AM)shiro26 Wrote:### GET THE 3 USER ANSWERS #============================== def get_names(): userlist = [] #setup to contain only lower case data print("List any 3 of the first 20 elements in the Period table.") while len(userlist)<3: userinput = input("Enter the name of an element:\t") if userinput.isalpha: <----- 1 if userlist.count(userinput) == 0: <----- 2 userlist.append(userinput.lower()) #print(userinput.title() + "was already entered, no duplicates allowed.") else: print(userinput.title() + "was already entered, no duplicates allowed.") #userlist.append(userinput.lower()) else: <----- 3 pass return userlist .....
- You are not calling a function - you are checking that
userinput.isalpha
is non-empty object (it is). Add brackets.
- You add lowercase string - but you check string as is. Lower-case the string before the test - and don't use count, use
in
operator
if userlist in userinput
- Redundant
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.