2015-08-21 19 views
0

好了,對不起,標題是不是很清楚,但我創建一個簡單的「你確定」在Python提示。基本流程是這樣的 -問「你確定」然後讓用戶正確不工作

[問IP]>用戶輸入< 0.0.0.1>

[Python中]:你確定0.0.0.1是正確的IP?您將無法在以後更改!

從現在開始,如果用戶說是的,那麼一切都OK。

然而,如果用戶沒有回覆,該腳本可以讓用戶重新輸入IP。當提示再次更正時,如果用戶現在確認它沒問題,那麼該腳本將返回None作爲IP變量。這裏是我的代碼...

def get_thingies(): 
    YesNoIP = "none" 
    while YesNoIP != "y" and YesNoIP != "n": 
     try: 
      temp = raw_input('Do you have an IP/domain name? Y/N: ').lower() 
      if temp != "y" and temp != "n": 
       print('Please enter Y or N') 
      else: 
       YesNoIP=temp 
     except ValueError: 
      print('Please enter Y or N'); 
      YesNoIP = 'none' 
def askIP(): 
    TheIP = raw_input('Okay, what is it? E.X 112.13.141.9: ') 
    if AskYesNo('Are you sure '+TheIP+' is the correct IP? You will not be able to change this later!!') != True: 
     print('Ok, get it right this time!'); 
     askIP() 
    else: 
     return TheIP 
if YesNoIP == "n": 
    print(help_things[0]) 
else: 
    IPConf = askIP() 
    print(IPConf) 
get_thingies(); 

回答

1

當您遞歸調用askIP(),你不回它的價值。

def askIP(): 
    TheIP = raw_input('Okay, what is it? E.X 112.13.141.9: ') 
    if AskYesNo('Are you sure '+TheIP+' is the correct IP? You will not be able to change this later!!') != True: 
     print('Ok, get it right this time!'); 
     return askIP() 
    else: 
     return TheIP 
+0

對不起,遲到的答覆......非常感謝你! –