I want to read and write grades(numbers) after a certain subject tag(string). So I have everything but I can't figure out how to find the tag and write after without replacing the numbers that were after it.
So, for example, valid input would be:
MAT54324524342211
And what I have tried so far:
save = open("grades.txt", "w")
def add(x, y):
z = x / y * 100
return z
def calc_grade(perc):
if perc < 50:
return "1"
if perc < 60:
return "2"
if perc < 75:
return "3"
if perc < 90:
return "4"
if perc >= 90:
return "5"
def calc_command():
num1 = input("Input your points: ")
num2 = input("Input maximum points: ")
num3 = add(float(num1), float(num2))
grade = calc_grade(num3)
print("This is your result:", str(num3) + "%")
print("Your grade:", grade)
save.write(grade)
while True:
command = input("Input your command: ")
if command == "CALC":
calc_command()
if command == "EXIT":
break
Any ideas? Hey sorry this is the old version of my code. The new version was that after printing my grade here was save.write(grade). Program is not finished. The final idea is that i will get a bunch of subject tags in my txt file and then the user will pick for which subject is the grade.