我有麻烦让这个循环工作可以任何人帮助我吗?

时间:2017-06-16 00:39:53

标签: python

任何人都可以理解为什么如果回答不正确,这不会重置?

def loop1:
(print) ("Please Enter Your Name.")
myName = input(:)
(print) ("Hello " +myName)
(print) ("Would You Kindly Confirm If the Hatch Is Open Or Closed O/C") 
hacthStatus = input ()
if hacthStatus == ('C'):
    loop1()

1 个答案:

答案 0 :(得分:1)

您的代码没有缩进,而且您还没有正确定义函数

试试这个

def loop1():  
      print ("Please Enter Your Name.")
      myName = input(":")
      print ("Hello " +myName)
      print ("Would You Kindly Confirm If the Hatch Is Open Or Closed O/C") 
      hacthStatus = input ()
      if hacthStatus == 'C':
          loop1()

loop1()

以上代码相当于

hacthStatus = 'C'
while  hacthStatus == 'C':
      print ("Please Enter Your Name.")
      myName = input(":")
      print ("Hello " +myName)
      hacthStatus = input ("Would You Kindly Confirm If the Hatch Is Open Or Closed O/C\n")