-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsecond.py
More file actions
18 lines (16 loc) · 716 Bytes
/
second.py
File metadata and controls
18 lines (16 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Create a function that takes a filename and a string as parameter,
# And writes the string got as second parameter into the file 10 times.
# If the writing succeeds, the function should return True.
# If any problem raises with the file output, the function should not break, but return False.
# Example: when called with the following two parameters: "tree.txt", "apple",
# the function should write "appleappleapple" to the file "tree.txt", and return True.
def write_in_file(filename, word):
try:
f = open(filename, 'a')
f.write(10*word)
f.close()
success = True
except IOError:
success = False
return success
print(write_in_file('text.txt', 'parameter '))