-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.

bad_coder
  • 11,289
  • 20
  • 44
  • 72

1 Answers1

-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)