Ich habe versucht ein Stück Code und es hat gut funktioniert, aber das Problem ist, es hat einen file.write Wert, den ich in Zeilen getrennt haben möchte. aber es funktioniert nicht. der Code:Wie kann ich hier den Zeilenumbruch nutzen?
start = input('Enter your starting point:')
stop = input('enter your destination:')
count = input('Ticket count:')
p = 10 * int(count) #a + b
q = 20 * int(count)#a + c
r = 30 * int(count)#a + d
s = 10 * int(count)#b + c
t = 20 * int(count)#b + d
u = 10 * int(count)#c + d
if start == 'a' and stop == 'b':
file = open(r"C:\Users\the\Desktop\py\2.txt " , 'w+')
file.write('Location: '+ start +' > '+ stop +\
'Ticket count: '+ count +\
'Total fare: ' + str(p))
file.close()
print ('Your cost is usd ',p)
elif start == 'a' and stop == 'c':
file = open(r"C:\Users\the\Desktop\py\2.txt " , 'w+')
file.write('Location: '+ start +' > '+ stop +\
'Ticket count: '+ count +\
'Total fare: ' + str(q))
file.close()
print ('Your cost is usd ',q)
elif start == 'a' and stop == 'd':
file = open(r"C:\Users\the\Desktop\py\2.txt " , 'w+')
file.write('Location: '+ start +' > '+ stop +\
'Ticket count: '+ count +\
'Total fare: ' + str(r))
file.close()
print ('Your cost is usd ',r)
elif start == 'b' and stop == 'c':
file = open(r"C:\Users\the\Desktop\py\2.txt " , 'w+')
file.write('Location: '+ start +' > '+ stop +\
'Ticket count: '+ count +\
'Total fare: ' + str(s))
file.close()
print ('Your cost is usd ',s)
elif start == 'b' and stop == 'd':
file = open(r"C:\Users\the\Desktop\py\2.txt " , 'w+')
file.write('Location: '+ start +' > '+ stop +\
'Ticket count: '+ count +\
'Total fare: ' + str(t))
file.close()
print ('Your cost is usd ',t)
elif start == 'c' and stop == 'd':
file = open(r"C:\Users\the\Desktop\py\2.txt " , 'w+')
file.write('Location: '+ start +' > '+ stop +\
'Ticket count: '+ count +\
'Total fare: ' + str(u))
file.close()
print ('Your cost is usd ',u)
else:
print('you entered wrong values')
bitte eine Lösung gibt mir oder den Code beheben. eine Sache zu erwähnen, dass ich Neuling in Python und das ist mein erstes Programm, das ich versuche. hoffe, dies behoben zu haben.
hat gut funktioniert. danke –
Also bitte akzeptieren und upvote meine Antwort – nacho