Click here to Skip to main content
15,503,491 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Python
days = ["sunday","monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
answered = False
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 
            print((lst))      
    #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 also idk why above is not showing as a comment :(
    if answered == False:
         print("You typed days of week wrong! Try Again!")
def listToString(lst): 
  if 0 < 2:
    test = open('list.txt', 'w')
    print(test.write(lst))
    test.close()

So i'm asking user for input and must fit into days then store it in lst and then put it in a file list.txt except I don't want it to be a list i want it to be on seperate lines but it's not storing in my file for some reason which is quite annoying remember i dont want it to be a list when stored in file cause I can't really call on a item like that. first time using this site so go easy on me and leave down some suggestions :) have a good day

What I have tried:

I tried append and checked the file that I had and still nothing I typed was stored
Posted
Updated 2-Sep-21 14:37pm
v3

1 solution

The most obvious reason is that you don't call your listToString function at any point.
You declare it, but that doesn't cause it to be executed: Python Functions[^]
 
Share this answer
 
Comments
Brock Templer 7-May-21 10:17am    
@OriginalGriff so your saying to return it which I did before which I should have mentioned but I did alot so not much to remember so I did
return listTo string
and got nothing any other suggestions?
OriginalGriff 7-May-21 10:30am    
No, I'm saying you define it but don't call it!

Search your code for the string "listToString" and you will only find it once - when you define the function.

Follow the link I gave you - it includes examples.
Brock Templer 7-May-21 11:30am    
You gonna have to give an example I clicked the link and don't know what your talking about.
OriginalGriff 7-May-21 12:03pm    
1) Follow the link.
2) Read six short lines of text, to where it says "Example" in big letters.
3) Read the example on how to define a function.
4) Read on down, another three more short lines and you will find "Example" in big letters again.
5) Read the example: this time, calling a function.
6) Optionally (but recommended) read the rest of the article.

Excellent! You know know how to define and call a function in Python.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900