python - 当我在 while 循环中使用 GOTO 命令时它不起作用
问题描述
我正在尝试制作一个选择系统。我想使用 GOTO 命令。但它实际上不起作用。我已经在 pip 中安装了 goto 语句。
from goto import with_goto
print('Welcome to * sell system.')
print('Choose the action:\n(1) Buy *\n(2) Contact us\n(3) Exit')
# Choose the action
while action := input('> '):
if action in '1':
break
if action in '2':
print('Contact Us\n* is a brand of *')
break
if action in '3':
exit()
print('Only 1 and 2 allowed.')
# Choose the categories
if action in '1':
print('Choose categories of merchandises.\n(1) *\n(2) *')
print('Enter 0 to exit')
# Choose the merchandise (A while in a if)
while category := input('> '):
if category in '1':
label .choose_merchandises
print('Choose the merchandises.\n(1) *- *')
while merchandises := input('> '):
if merchandises in '1':
print('Title:*- *\nPrice: *\nAmount: *\nDetails:\nDo you wanna buy it?\n(y/n)')
while wannabuy := input('> '):
if wannabuy == "y":
print('Redirecting to pay...')
break
if wannabuy == "n":
goto .choose_merchandises
print('Only y or n allowed.')
print ('1')
if category in '2':
print('2')
break
print('Only 1 and 2 allowed.')
它告诉我
Traceback (most recent call last):
File "d:\*\*.py", line 18, in <module>
label .choose_merchandises
NameError: name 'label' is not defined
我能怎么做。欣赏。
补丁:我是python的初学者。它是一个选择系统,人们可以做他们想做的事情,比如联系我们,买东西等等。首先,用户选择像买东西,联系我们这样的动作。用户选择商品的类别,然后选择商品。
解决方案
推荐阅读
- java - Java - Orcale 无法为事务打开 JDBC 连接
- android - Android资源编译失败-AAPT错误-资源重复值
- php - ReactJS axios POST 请求将所有选项作为具有空值的单个 JSON 键发送
- javascript - Js 谷歌地图标记和路径不出现
- ruby-on-rails - Rails 如何同时回滚和渲染?
- android - 为什么 Bundle 中的字符串在 Android 中被修改?
- r - 应用族函数不适用于 group_by() 但它适用于 select()
- python - 带变量的 PLT Latex
- android - 软键盘显示时约束布局方向改变
- javascript - Bootstrap对齐的下拉菜单