python - 如何在不结束整个程序的情况下退出函数?(Python)
问题描述
我正在尝试对我正在制作的游戏进行重新滚动功能,但是当它询问“你想再次滚动吗?”时,它不会接受否定的答案。循环继续,好像我回答是。我正在使用类型计数器来控制可以重新滚动的次数,因此我尝试将计数器设置为高于允许的数量,但这不起作用。计数器确实允许重新滚动,直到超过允许的数量,所以这似乎不是问题。
for i in range(6):
#rolls 6 faces of a die and sets them to a "hand"
if counter == 0:
print("1",hand1,"\n","\nYou earned",resolve1,"resolve")
else:
print("\n1",hand1,"\n","\nYou earned",resolve1,"resolve")
counter = counter + 1
if counter < 3:
yn = input("\nDo you want to roll again? (Y/n)\n")
if yn == "y" or "Y":
hand1 = []
resolve1 = 0
elif yn == "n" or "N":
counter = 4
else:
print("\nYou cannot reroll\n")
counter = 4
顺便说一句,我几乎是个新手,几年前刚在 GCSE 学习计算机科学。
解决方案
尝试返回一个值或使用break 关键字。
推荐阅读
- angular - 预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段 Access-Control-Allow-Methods
- python - 使用两个不同的参数同时最小化两个成本函数
- c - Visual Studio:回调函数问题(__cdecl *)
- r - 如何获取列表第一级的变量名称?
- browser - Adobe Sign - 无云
- java - Jackson DateFormatter 设置时区而不更改时间
- python - 有什么类似于 Python 在 c++ 中的索引吗?
- java - 如何清除导航标题视图?
- javascript - CSS 变换旋转仅适用于 Firefox
- angular - “对象”类型上不存在属性“数据”