Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions fix_exercise_number.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import fileinput
counter = 1

input_file = input('Please enter the name of the file you want to edit: ')

# fileinput module let us do changes in the same file
with fileinput.FileInput(files=input_file, inplace=True) as f:
for line in f:
if line.startswith('# ex.'):
replace_line = line
new_line = ('# ex.{}'.format(counter))
print(line.replace(replace_line, new_line))
counter += 1
else:
print(line.strip()) # .strip() remove the extra blank lines

print('Editing {} successfully'.format(input_file))
'''
ex.1:
Create two variables a and b, and initially set them each to a different number. Write a program that swaps both values.
'''

import numpy as np

a = input('Please enter number a: ')

b = input('Please enter number b: ')

a, b = int(a), int(b)

an_array = np.array([a, b])

a, b = int(an_array[1]), int(an_array[0])


print(f'''
a: {a}

b: {b}
''')