Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The Python File Consists of the follwing...
- def file_math(filename):
- with open(rf"{filename}.in") as file0:
- data = file0.readlines()
- with open(rf"{filename}.out", 'w') as file:
- for i in data:
- L1 = i.split()
- if L1[0] in ('ADD', 'SUB', 'MUL', 'POW'):
- if L1[0] == 'ADD':
- file.write(f"{L1[1]} + {L1[2]} = {int(L1[1])+int(L1[2])}\n")
- elif L1[0] == 'SUB':
- file.write(f"{L1[1]} - {L1[2]} = {int(L1[1])-int(L1[2])}\n")
- elif L1[0] == 'MUL':
- file.write(f"{L1[1]} X {L1[2]} = {int(L1[1])*int(L1[2])}\n")
- elif L1[0] == 'POW':
- file.write(f"{L1[1]} ^ {L1[2]} = {int(L1[1])**int(L1[2])}\n")
- else:
- file.write("Invalid Operation\n")
- print("File Successfully Read and Written...")
- file_math("filename")
- # Contents of the file named "filename.in"
- ADD 34 56
- SUB 28 35
- MUL 30 45
- POW 23 45
- CHK 23 34
- MOD 23 45
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement