Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python菜单集成错误_Python_Syntax_Menu - Fatal编程技术网

Python菜单集成错误

Python菜单集成错误,python,syntax,menu,Python,Syntax,Menu,所以,我一直在尝试用Python制作一个Skype多功能工具,我刚刚开始使用它。我有一个程序的代码可以运行,但我不知道如何将它放入菜单 以下是我得到的代码: import time import urllib2 ans=True while ans: print(""" 1. Skype resolver 2. Option 2 3. Option 3 4.Exit/Quit """) ans=raw_input("What would you like to do? ") if ans=="1

所以,我一直在尝试用Python制作一个Skype多功能工具,我刚刚开始使用它。我有一个程序的代码可以运行,但我不知道如何将它放入菜单

以下是我得到的代码:

import time
import urllib2
ans=True
while ans:
print("""
1. Skype resolver
2. Option 2
3. Option 3
4.Exit/Quit
""")
ans=raw_input("What would you like to do? ")
if ans=="1":(
def getSkype():
input = '> '
print "Please enter a skype name: "
skypename = raw_input(input)
print "Skype name: %s" % skypename
time.sleep(2.5)
url = "http://APIOnly.com/skype.php?username=%s" % skypename
req = urllib2.Request(url)
response = urllib2.urlopen(req)
return response.read()

if __name__ == "__main__":
skypeip = getSkype()
print "IP: %s" % skypeip
print "Press [Enter] to continue"
raw_input()
 )
  time.sleep(20)
elif ans=="2":
  print("Option 2")
elif ans=="3":
  print("\n Option 3")
elif ans=="4":
  print("\n Goodbye") 
  ans = None
else:
       print("\n Not Valid Choice Try again")
它告诉我,
def
是无效语法


如何修复此问题以及我做错了什么?

这是一个正确缩进的代码。但是,不要忘记,在Python中,代码的缩进具有语义意义,因此您无法获得“非缩进”代码


请修正你的缩进。为什么要在if语句中定义函数?在哪里?对不起,我刚开始学习python。。。
import time
import urllib2

ans=True

while ans:
    print("""
      1. Skype resolver
      2. Option 2
      3. Option 3
      4.Exit/Quit
    """)
    ans=raw_input("What would you like to do? ")
    if ans=="1":(
        def getSkype():
            input = '> '
            print("Please enter a skype name: ")
            skypename = raw_input(input)
            print("Skype name: %s" % skypename)
            time.sleep(2.5)
            url = "http://APIOnly.com/skype.php?username=%s" % skypename
            req = urllib2.Request(url)
            response = urllib2.urlopen(req)
            return response.read()

        if __name__ == "__main__":
            skypeip = getSkype()
            print("IP: %s" % skypeip)
            print("Press [Enter] to continue")
            raw_input()
        )
        time.sleep(20)
    elif ans=="2":
        print("Option 2")
    elif ans=="3":
        print("\n Option 3")
    elif ans=="4":
        print("\n Goodbye") 
        ans = None
    else:
        print("\n Not Valid Choice Try again")