Write a Python program that asks user for name of the file and text that file should contain. Create a text file with given name and fill it with text that entered by user. Input:

Enter a file name: sample
Enter a text of the file: This file was created at informatics lesson by using
Python programming language.

veragmyr veragmyr    2   04.03.2021 05:56    0

Ответы
vabimGogolev vabimGogolev  03.04.2021 05:57
Code:

name = input("Enter a file name: ") + ".txt"

text = input("Enter a text of the file: ")

with open(name, "w") as file:

   file.write(text)

Output:

Enter a file name: abc                                                                                                        

Enter a text of the file: 12345

abc.txt file is created with the text: 12345

ПОКАЗАТЬ ОТВЕТЫ
Другие вопросы по теме Информатика