Задача заключалась в том, чтобы позволить пользователю выбрать либо прочитать файл данных, либо записать в файл данных. Я понял, как писать, но я не могу понять мою текущую ошибку: мой список выходит за пределы допустимого диапазона.Python - Как мой список выходит за пределы диапазона?
Может ли кто-нибудь сказать мне, как мой список выходит за пределы допустимого диапазона?
Я уверен, что все правильно, но я честно не знаю, как мой список выходит за пределы диапазона. Пожалуйста, помогите мне, ребята. Благодаря!
#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)
У какой строки есть ошибка? – shruti1810
Нам нужно больше деталей, чем это. Какая линия? Что вы пробовали? Какие примеры? – Tux
Вы можете вставить трассировку ошибки? –