Python菜单集成

2024-04-26 07:10:01 发布

您现在位置:Python中文网/ 问答频道 /正文

所以,我一直在尝试用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是一个无效的语法。你知道吗

我该如何解决这个问题?我做错了什么?你知道吗


Tags: to代码nameimportinputrawiftime
1条回答
网友
1楼 · 发布于 2024-04-26 07:10:01

这是一个正确缩进的代码。但是,不要忘记,在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")

相关问题 更多 >