-1
"""10-3. Guest: Write a program that prompts the user for their name. When they respond, write their name to a file called guest.txt.""" filename2 = "../Data/guest.txt" with open(filename2, "w") as guest_info: filename = input(str(guest_info)) for info in guest_info: print(f"name: {info}") 

I already created empty txt file. I need to let user fill with info. How would you solve this?

10-3. Guest: Write a program that prompts the user for their name. When they respond, write their name to a file called guest.txt.""" filename2 = "../Data/guest.txt" with open(filename2, "w") as guest_info: filename = input(str(guest_info)) for info in guest_info: print(f"name: {info}") 

I was expecting, that input would work but it says it isn't readable.

0

1 Answer 1

-1

Take a look at the responses to this question: reading and writing to the same file simultaneously in python

It is possible to perform read and write operations with w+, you may find it more straightforward to add the new entry in write mode, then open in read mode to check the contents.

Double-check how you are working with your input function. The value you pass into the str() function is the prompt that will be displayed. e.g. to prompt for a name and enter it into your file, the following is a common approach:

filename = input(str("what is your name? ")) guest_info.write(filename) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.