Python在列表中拆分变量

时间:2017-02-23 20:31:59

标签: python

我目前制作了一个python程序,它应该接受用户输入,找到关键字并找到一个文本。一个问题:它不起作用。代码如下:

import time
import sys
e=0
brokenscreen= "crack cracked smashed".split()
newtest= "turning turn".split()
buttons= "buttons button".split()
sound= "sound speaker volume".split()
frozen= "frozen unresponsive responding".split()
WiFi= "wi-fi wifi disconnecting wifi".split()
memory= "memory data".split()
removeapps= "uninstall removeapps appremove uninstal apps app".split()
wipe= "completerestart restart wipe".split()
water= "water wet".split()
camera= "camera cam".split()
bad= "bad rubbish terrible".split()
black= "black calls".split()
notifications= "notifications"
anlist=[brokenscreen, newtest, buttons, sound, frozen, WiFi, memory,         removeapps, wipe, water, camera, bad, black, notifications]
anPrint=[
"You need to repair it in a store.",
"Check that it has full charge, or check it is definately charging. You will         need to take it to the store to get it checked.",
"Button Savior will bring your phone hardware keys to your home screen.     After you install and run the app, you will see a small pull out arrow on the right edge of the screen.\n Tap on it and yu should have buttons on screen.",
"If your phone suffer from low volume then you can download AudioBoost from the market. It can increase the volume up to 30% and is also activated from home screen widget.",
"You just need to restart your phone to kickstart a frozen phone.",
"This may solve the problem. Just go to Wi-Fi > Settings > Menu > Advanced and choose to stay connected to Wi-Fi during sleep.",
"Among other reasons, the most prominent problem can be a full cache which affects the efficient running of apps. You can download apps like Cache Cleaner or Clean Master from Google Play",
"Go to Settings > Applications > Manage Applications and then select the app you wish to uninstall. Now tap the Uninstall icon to remove the app.",
"Go to Settings > SD & Phone storage > Factory Data Restore. Go through the process twice to be completely sure that everything has been removed.",
"Take the battery out as quickly as possible and dry as many parts of the phone as you can then leave it for 72 hours in a dry room. \n Try it again, it may work. Also try putting the phone and components into a bowl of rice.",
"If the camera doesn't work, let the camera take the photo at the default resolution, then scale it to your preferred size in an AsyncTask, an app on the app store.",
"I'd reccomend android. Anything but apple. Get a new phone.",
"Some people have reported success by pushing on the screen where the proximity sensor is located, which suggests a build issue. There is no fix for this issue yet.",
"Check your Wi-Fi or data connection. Poor coverage will impact on push notifications. Go to Settings > Wi-Fi > Advanced and tick the box next to Keep WiFi on when screen times out."
]

def restart():
    yes_no=input("Restart? (Y/n): ").lower()
    if yes_no:
       return yes_no[0] == 'y'
    return True

def program(pos):
    if z=="an" or z=="and" or z=="android":
          for word in a:
              item=anlist[pos]
              if word in item:
                  print(anPrint[pos])
                  time.sleep(0.5)
                  pos=pos+1
              elif word not in anlist:
                  pos=pos+1
                  sys.exit
    return pos

while True:
    z=input("ANDROID™ TROUBLESHOOTING (Alpha Testing 0.9.5) Enter the word 'Android': ")
    if z=="and" or z=="an" or z=="android":
        a=input("Describe your problem please: ").lower().split()
        program(e)
        restart()
    else:
        print("No valid input detected.")
        restart()
if not restart():
    break

当我使用类似1关键字的东西时,它的效果非常好,它会找到与之相关的句子并且几乎完美地执行,但是当我尝试重新启动时会遇到问题(标记为“重复问题”)并实际打印出来用户写句子时的语句。感谢所有人的帮助

编辑:修正重启

0 个答案:

没有答案