Ավելացում ֆայլին

Հիշենք ֆայլերի հետ աշխատելու մի քանի տարբեր ռեժիմները.
Ռեժիմ
Գործողություն
Օրինակ
'r'
Կարդալ
with open('document.txt', 'r') as f:
'w'
Գրել
with open('document.txt', 'w') as f:
'a'
Ավելացնել
with open('document.txt', 'a') as f:
'r+'
Կարդալ + Գրել
with open('document.txt', 'r+') as f:
'x'
Ստեղծել (սխալ, եթե առկա է)
with open('document.txt', 'x') as f:
Համակարգչում կան տարբեր ֆայլեր: Ձեզ խնդրում են դրանցում ավելացնել մի քանի տող:
Մուտքը պարունակում է 2 տող: Առաջին տողը ֆայլի անունն է: Երկրորդը բովանդակությունն է, որը մենք կցանկանայինք ավելացնել այդ ֆայլին:
Ծրագիրը նախ պետք է ֆայլին ավելացնի նշված տողը, այնուհետև տպի ֆայլի ամբողջ բովանդակությունը:
Input
doc.txt (initial content)
Output
doc.txt (resulting content)
doc.txt This is the second line
This is the first line
This is the first line This is the second line
This is the first line This is the second line
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue