python - 将用户返回到上一行
问题描述
我试图让代码根据用户提供的输入将用户返回到前一行代码。如果他们回答“不”或“不是真的”等,当我问他们是否理解规则时,我希望他们回到前面的代码行并再次阅读。
print("Ok, the rules of this 'game' are very simple; You are kind of doing a virtual house tour.")
print("You will be inspecting the house for its condition and to see if it is 'sellable'.")
print("You will be going from room to room and checking it out based on the room description I give.")
print("You will be giving each room a number value of 0,1,2, or 3. A 0 takes away from the value of the house.")
print("A 1 doesn't change the value of the house. A 2 or a 3 increase the value of the house.")
print("If at any point in the tour you think the house is not 'sellable', you just have to say so and the game ends.")
print("Your progress in the house will be tracked at all times.")
ans2=input("Understand? Are you ready?")
if ans2.lower() in Accept_ans:
print ("Ok, great! Lets begin the tour.")
else:
print("ok, read the instructions again")
解决方案
如果答案不符合预期,请使用while
循环返回起点。
ok = 0
while not ok:
print("Ok, the rules of this 'game' are very simple; You are kind of doing a virtual house tour.")
print("You will be inspecting the house for its condition and to see if it is 'sellable'.")
print("You will be going from room to room and checking it out based on the room description I give.")
print("You will be giving each room a number value of 0,1,2, or 3. A 0 takes away from the value of the house.")
print("A 1 doesn't change the value of the house. A 2 or a 3 increase the value of the house.")
print("If at any point in the tour you think the house is not 'sellable', you just have to say so and the game ends.")
print("Your progress in the house will be tracked at all times.")
ans2=input("Understand? Are you ready?")
if ans2.lower() in Accept_ans:
print ("Ok, great! Lets begin the tour.")
ok = 1
else:
print("ok, read the instructions again")
推荐阅读
- java - 如果没有从父存储库显式刷新,对父的修改不会持久
- linux - 作为 shell 脚本的一部分,sudo su 不起作用。有替代品吗?
- javascript - 当xxx是孩子时处理javascript“无法读取未定义的属性'xxx'”
- selenium-webdriver - 如何在 Selenium Webdriver 中定位 CKEditor,以及 CK Editor 中的 iframe 和 body 是什么
- r - ggplot中没有边框的圆形
- listview - 为什么 DataContext 为 ListView 项目之外的项目返回空值?
- bash - 新行文本的 sed 错误未终止替换模式
- c++ - 通过实用程序 fn 将捕获的 lambda 传递给 C 样式回调 - 错误
- css - 警告:validateDOMNesting(...):不能作为后代出现
- google-cloud-platform - 要求 BigQuery 视图上的分区过滤器