Kullanıcı tarafından girilen bir ürün için bir metin dosyası aramak için kodumu almaya çalışıyorum, ancak istediğim gibi tüm satırı değil, yalnızca ilk satırı okuyor. İşte Python'u sadece bir satır değil, bütün bir metin dosyasını okumak için nasıl edinirsiniz?
benim kodudur:order=input("Please enter the name of the product you wish to purchase\n")
myfile=open("barcode.txt","r")
details=myfile.readlines() #reads the file and stores it as the variable 'details'
for line in details:
if order in line: #if the barcode is in the line it stores the line as 'productline'
productline=line
quantity=int(input("How much of the product do you wish to purchase?\n"))
itemsplit=productline.split(' ') #seperates into different words
price=float(itemsplit[1]) #the price is the second part of the line
total=(price)*(quantity) #this works out the price
print("Your total spent on this product is: " +'£'+str(total))
else:
break
Siparişi ilk satırda bulamazsanız, döngüden koparsınız. – Selcuk
Sadece bir satır almanızın sebebi, – Tgsmith61591
'u "pass" ile değiştirirseniz veya – Whitefret