How do you save the inputs into text file?

Gazzer

How do i save the inputs of program into a file from the program. Python only: i need to add it to this:

TASK 2 AGAIN

sentence = input("Please input a sentence: ")
print(sentence)
word=input("Please enter word and position wil be shown: ")
if word in sentence:
    print("Found word")
else:
    print ("Word not found")

But i haven't got a clue

pat

Your question seems to have two main parts to it: how do I get inputs in Python and how do I save data to a file in Python.

To get input from the terminal:

>>> data = input('Input: ')
>>> Input: hello, world!

To save to a file:

>>> with open('output.txt', 'w') as f:
>>>    f.write(data)

You can find more information about inputs here and file i/o here

Edit 0: @Gazzer, if you want to save sentence + input you'll need to do f.write(sentence + input) rather than using .save().

Edit 1: @Gazzer, I got something like the below to work (note: the code does not show position of the found word):

sentence = input("Please input a sentence: ")
word = input("Please enter word and position wil be shown: ")
with open('output.txt', 'w') as f:
    f.write('{} {}'.format(sentence, word))

If you run into more issues, there are hundreds of resources all over the web to ask for help. Stack Overflow, learnprogramming, and many more.

Next time you ask a question, it is really helpful for those answering if you provide a code snippet you are working on and what the problem/errors are.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do you save a LibreOffice Writer file as plain text?

how i can save inputs from html page to text file

how do i save three inputs to a file with same name as the user?

How do you save a Tensorflow dataset to a file?

How do you save a file to a directory given by an input type="text" with php?

How do you save the text in the terminal to various text formats?

How do you import a text file into typescript?

How do you add text in a Batch File?

How do I save a Save/Load a text file in Red

How do you print output and save in a file using list comprehension?

In IPython, how do you save and append to a file rather than overwriting it?

How do you save edited csv file in a subfolder

How to use AJAX with file and text inputs?

How do I save JSON to local text file

How do I save the text of puts in Ruby to a txt file?

How do I save printer settings as a text file

How do I read a text file image and save it to an array?

How do I save specific text in an array from .txt file

How do I save form data to a text file?

How do I create and save to a text file using PHP?

Python: How do I save generator output into text file?

How do I save output into a text file in python?

How do you pull specific information out of a text file? Python

How do you add characters to a line in python in an existing text file?

How do you protect a plain text credentials file with the username and password?

How do you execute a lua file in sublime text 3?

How do you compare the content of an edit control to the text in a file?

How do you print to a text file in GAP without linebreaks?

How do you search for a certain thing in a text file in python?