如何解决我想在Python中重复必要的if语句
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。