When I run this Python code I get a NameError. But in this code I'm trying to get a variable defined in a for loop (get) to use in outside of the loop. How can I use this variable (get) outside in for loop?
file = open("f:/py/price.txt", "r")
valRange = 0
cal = 0
totalCst = 0
itmCnt = 0
while (valRange < 10):
idNumber = int(input("Enter Id number: "))
for line in file:
if line.startswith(str(idNumber)):
get = line.split("=")[1]
break
quantity = int(input("Enter qantity: "))
cal = quantity * int(get)
totalCst += cal
itmCnt += quantity
print (totalCst)