如有必要,我想在 python 中重复某个 if 语句

i want to repeat a certain if statement if necessary in python

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>

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

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

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