how to save user input to a text file in python code example
Example 1: how to write user input to a file in python
x = input("Enter blah : ")
y = open('C:\Users\USERNAME\Documents\Doc1.txt', 'w')
y.write(x)
x = input("Enter blah : ")
y = open('C:\Users\USERNAME\Documents\Doc1.txt', 'wb')
y.write(x)
Example 2: python save input to text file
print('My Mood Diary')
mood = input('How are you feeling today? ')
text_file = open("MoodDiary.txt", "w")
text_file.write(mood)
text_file.close()
Example 3: how to take user input and create a file in python
import os
os.remove(“file.txt”)