【问题标题】:i want to repeat a certain if statement if necessary in python如果需要,我想在 python 中重复某个 if 语句
【发布时间】:2020-11-02 12:50:44
【问题描述】:
elif opt==2:
    nitem=str(input('enter the porduct name'))
    nitemc=int(input('enter the item code'))
    nstkq=int(input('enter stock qty'))
    nitemtyp=str(input('enter item type'))
    b={'itemname':nitem,'itemcode':nitemc,'item-type':nitemtyp,'stock':nstkq}
    stock=stock.append(b ,ignore_index=True)
    x=str(input('do you want to add another one? \n "y" for yes "n" for no' ))
    if x=='y':
        <to repeat>

我应该使用什么代码让代码在用户要求的时间内重复多次?

希望我能得到帮助谢谢!!!!!!!

【问题讨论】:

  • 一个循环怎么样?

标签: python command keyword


【解决方案1】:
elif opt==2:
    while True:
        nitem=str(input('enter the porduct name'))
        nitemc=int(input('enter the item code'))
        nstkq=int(input('enter stock qty'))
        nitemtyp=str(input('enter item type'))
        b={'itemname':nitem,'itemcode':nitemc,'item-type':nitemtyp,'stock':nstkq}
        stock=stock.append(b ,ignore_index=True)
        x=str(input('do you want to add another one? \n "y" for yes "n" for no' ))
        if x=='n':
            break

【讨论】:

    猜你喜欢
    • 2016-08-05
    • 2019-01-04
    • 2017-10-25
    • 1970-01-01
    • 2018-08-24
    • 1970-01-01
    • 2016-11-20
    • 1970-01-01
    • 2017-10-13
    相关资源
    最近更新 更多