so im stuck with this code, point of it is that you enter car name and amount of car that you want to rent but i can figure out how to change string in .txt file after you rent cars
def rental():
with open('cars.txt', 'r') as file: # cars.txt example:
# bmw:320:red:new:6
name = input('Car name: ')
for line in file:
s = line.split(':')`enter code here`
if name == s[0] :
amount = eval(input('Amount of cars'))
if amount > int(s[4]):
print('Amount is too big')
else:
t = str(int(s[4])-int(kolicina))
line.replace(s[4], t)
else:
print('Car does not exist')