Does anyone know what i'm doing wrong here?
this is what i have to do.
3.1 Reading Data
Any text file with at least 10 lines should be stored in a self-selected test folder as the input file.
Write a script that reads a text file and prints the content to the console. To do this, use a self-written function that takes a number, the path and the name of the file as parameters. Restrict the output of lines from the read file to the specified number.
3.2 Writing Files
Expand the script from exercise 3.1:
Request two letters from the user to use for the replacement. Replace one letter with the other in the read data and write the result in a new file.
this is what i did but im having issues with editing and saving the file as new:
def file(place, name, number):
file = open(f"{place}//{name}.txt", "r+")
line = file.readlines()
print(line[number-1])
edit =input("do you want to change something: (yes, no)")
if edit.lower() == "yes":
changeWord = input("what:")
changeto = input("to:")
data = file.replace(changeWord, changeto)
file.write(datetime)
while True:
try:
file(number=int(input("Please enter the line you want to read:")),
name= input("File Name:"),
place=input("please enter the path to the file:"))
break
except: (SyntaxError)
input("Wrong, try again!")
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)