while while循环输入2 if语句

时间:2017-10-29 00:23:18

标签: c#

我有以下代码,一次返回2个参数。也就是说,如果我输入-25,我会得到两个结果,我只想要一个说明你得到的结果" 0"以0的速度。

enter image description here

for ownerfile in ownerfile_list:
    if ownerfile.endswith(".csv"):
        each_file = (file_path + ownerfile)
        print(ownerfile) # file we're working on.

        with open(each_file, 'r', encoding = "UTF-8") as input_file : 

            next(input_file) # skip headers

            if not os.path.isdir(ownerfile) and not ownerfile.startswith("_"):

                for idx, line in enumerate(input_file.readlines()) :

                    line = line.strip().split(',')
                    cur.execute('''
                        INSERT INTO transactions (datetime,register_no,emp_no,
                          trans_no,upc,description,trans_type,trans_subtype,
                          trans_status,department,quantity,Scale,cost,unitPrice,
                          total,regPrice,altPrice,tax,taxexempt,foodstamp,wicable,
                          discount,memDiscount,discountable,discounttype,voided,percentDiscount,
                          ItemQtty,volDiscType,volume,
                          VolSpecial,mixMatch,matched,memType,staff,numflag,itemstatus,tenderstatus,
                          charflag,varflag,batchHeaderID,local,organic,display,receipt,
                          card_no,store,branch,match_id,trans_id)
                        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
                        ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
                        ?,?,?,?,?,?,?,?,?,?,?,?,?)''', line)   
db.commit()

1 个答案:

答案 0 :(得分:3)

在第二个条件语句中使用else if代替if

if (sentinel >= -998 && sentinel <= 0)
{
    WriteLine("At 0 pieces at $0.00 per piece, you've earned $0.00.");
}
else if (sentinel >= 1 && sentinel <= 49)
{
    WriteLine("At {0} pieces at {1} per piece, you've earned {2}.\n", sentinel, fifty, sumfifty);
}
else if (sentinel >= 50 && sentinel <= 100)
{
    WriteLine("At {0} pieces at {1} per piece, you've earned {2}.\n", sentinel, hundred, sumhundred);
}
else
{
    WriteLine("At {0} pieces at {1} per piece, you've earned {2}.\n", sentinel, overhundred, sumoverhundred);
}