The assignment was to let the user choose to either read the data file or to write to the data file. I figured out how to write to it but I cannot understand my current error: that my list is out of range.
Can someone tell me how my list is out of range?
I've done everything right, I believe, but I'm honestly not sure how my list is out of range. Please help me guys. Thanks!
#Run again
useAgain=bool(True)
while useAgain:
#Display Options
print("\nYou may either read or write to the file:\n"\
"\n'1' - To read and display records in the data file."\
"\n'2' - To order.\n")
choice=str(input("Please enter your choice here: "))
def func_read():
cs7Assn7=open("cs7Assn7.txt",'r')
line=cs7Assn7.readline()
places=line.split('+')
userID=places[0]
widgetsNum=places[1]
gidgetsNum=places[2]
doodadsNum=places[3]
print("Customer ID: ",userID,"\nNumber of Widgets: ",widgetsNum,\
"\nNumber of Gidgets: ",gidgetsNum,"\nNumber of Doodads: ",\
doodadsNum,"\n")
def func_order():
userID=str(input("Please enter your user ID(2 letters"\
" followed by 3 numbers: "))
widgetsNum=abs(int(input("Number of Widgets you would"\
" like to order: ")))
gidgetsNum=abs(int(input("Number of Gidgets you would"\
" like to order: ")))
doodadsNum=abs(int(input("Number of Doodads you would"\
" like to order: ")))
items=open("cs7Assn7.txt",'a')
items.write(str(userID) + str(abs(widgetsNum)) + str(abs(gidgetsNum))\
+ str(abs(doodadsNum)) + '\n')
items.close()
if choice=="1":
func_read()
elif choice=="2":
func_order()
useAgain=str(input("\nWould you like to run this code again? Type 'Y' to"\
" run or 'N' to stop: "))
useAgain=useAgain.lower()
if useAgain !="y":
useAgain=bool(False)