0

I wanted to keep title short. My goal is to create a calender type. the code I did was

days = ["sunday","monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
userInput = input("What day of the week would you like to assign a event: ")
lst = []
input_words=userInput.lower().split()
for word in input_words:
    if word in days:
        print(word.append(lst))
    else:
      print("You typed days of week wrong! Try Again!")
      

As you see I wanted to make 'userInput' only allowed too type in the items in 'days' which worked i think. The problem with the code is when I do run it it says attribute error 'str'object has no attribute 'append' and yes i tried other things such as insert but same thing. also I tried my best to make this clear for anyone helping so other than grammar any suggestions on improvement. Hope you have a good day!

jeffy
  • 31
  • 7

1 Answers1

1

The syntax for appending an item to a list is

list_variable.append(item_to_add)

Right now, in your code it is reversed.

Also, I recommend breaking out the print statement from the appending line.

days = ["sunday","monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
# set variable answered to be false to facilitate while loop
answered = False

# check to see value of answered
while answered == False:


    userInput = input("What day of the week would you like to assign a event: ")
    lst = []
    input_words=userInput.lower().split()
    for word in input_words:
        if word in days:
            lst.append(word)
            print(word)
            # set answered to True boolean
            answered = True
            
    # only evaulated after reviewing all words, if True is not set, prompts user again and let's them know that their answer is not valid
    if answered == False:
         print("You typed days of week wrong! Try Again!")



Joe Thor
  • 1,164
  • 1
  • 11
  • 19
  • Hello It seemed your code worked but how do you think I make it repeat the question again if it gets it wrong as in afer it prints you typed it wrong how do i get it to reepead the same question without bugs – jeffy May 05 '21 at 17:25
  • You can put all the logic in a while loop, which I have updated my answer to include. While loops may not be best practice, but it will work for these purposes. I recommend reading this answer: https://stackoverflow.com/a/23294659/4352317 – Joe Thor May 05 '21 at 17:49
  • Thank you for your help I have been pushing foward! :) – jeffy May 06 '21 at 12:32