在Python 3中出现值错误问题

问题描述

我正在编写一个测试程序,该程序类似于出租店的库存跟踪器。 我正在检查用户输入的数据,但我的其中一个if语句正在检查条目,从而不断出现ValueError。

def check_entries (): #This function checks whether what the user entered is correct for the entry and store

global customer_name_error_label
global receipt_numb_error_label
global item_hired_name_error_label
global numb_items_hired_error_label
global numb_items_hired_numb_rel_error_label

if  customer_name_entry.get () .isalpha ()  and   receipt_number_entry.get().isdigit() and  item_hired_entry.get () .isalpha ():
    if number_of_items_hired_entry.get () .isdigit () and int (number_of_items_hired_entry.get () ) >0 and int (number_of_items_hired_entry.get () )  <500:

        customer_name_error_label.grid_forget ()
        receipt_numb_error_label.grid_forget ()
        item_hired_name_error_label.grid_forget ()
        numb_items_hired_error_label.grid_forget ()
        numb_items_hired_numb_rel_error_label.grid_forget ()
        append_lists ()


else: 

       if customer_name_entry.get () .isalpha () ==False:
        customer_name_error_label=Label (main_frame,text="Please enter a name that only has letters,no numbers,and there must be a name entered ",bg='red')
        customer_name_error_label.grid (row=0,column=3)
 
        if receipt_number_entry.get () .isdigit() ==False:
            receipt_numb_error_label=Label (main_frame,text="Please enter a receipt number that is only a number and doesn't have any letters or symbols.",bg='red')
            receipt_numb_error_label.grid(row=1,column=3)

        if item_hired_entry.get () .isalpha ()== False:
            item_hired_name_error_label=Label (main_frame,text="Please enter a item name that only has letters,numbers and symbols aren't accepted.",bg='red')
            item_hired_name_error_label.grid (row=2,column=3)
       
       if number_of_items_hired_entry.get ().isdigit ()== False:
           numb_items_hired_error_label=Label (main_frame,text="The number of items hired can only be a number,symbols,and letters aren't accepted.",bg='red')
           numb_items_hired_error_label.grid (row=4,column=3)

       if int (number_of_items_hired_entry.get () ) <0 and int (number_of_items_hired_entry.get () ) >500:
           numb_items_hired_numb_rel_error_label=Label (main_frame,text="The number of items hired can only be more then 0 and less then 500",bg='red')
           numb_items_hired_numb_rel_error_label.grid (row=5,column=2)

有一幅图片显示我正在为所有条目输入一个空字符串,然后按附加详细信息按钮。]

There is an image of what I'm entering,its an empty string for all the entries and then I'm pressing the append details button.

这是错误 if int (number_of_items_hired_entry.get () ) <0 and int (number_of_items_hired_entry.get () ) >500: ValueError: invalid literal for int() with base 10: ''

解决方法

    PRODUCT PRICE PURCHASE
0   ABC 5000    TRUE
1   ABB 2500    FALSE
2   ABE 1800    FALSE
3   DCB 7200    TRUE