繁体   English   中英

Python中的故障排除程序。 如何链接Qs?

[英]Troubleshooting Program in Python. How to link Qs?

我在这里问有关我正在处理的代码的另一个问题。 我不断收到无效的语法错误。 我在另一个帐户上问了类似的问题,有人回答了这个问题并给了我一个密码。 我对其进行了编辑,但似乎无法解决。 我的项目是为移动公司制定故障排除程序。 目前,这是我的代码:

码:

print("Please answer 'yes' or 'no' to all questions. If you write something  else instead of yes or no then your solution might not come out correctly.")
solution = "Keep holding the power on button until the screen is on. If it  doesn't turn on, contact your phone provider to get a replacement."
solution2 = "Charge your phone fully and switch it on."
solution3 = "Delete some apps, you need a minimum of at least 5 GB of free  memory to run the phone correcly.\nYou are probably out of memory."
sol4 = "Take out everything from the phone and put it in a bag of rice for  24-36 hours to let the rice absorb the water."
sol5 = "Reset your phone."
sol6 = "You need a screen replacement. Get it fixed!"
sol7 = "You need to get your buttons replaced!"
sol8 = "Get a screen replacement or contact your phone provider to get a  phone replacement."
sol9 = "You need to update your phone software and apps."
sol10 = "You dont need to do anything. Your phone doesnt have any problems."
sol11 = "Please update your phone software."

  if input("Did you buy your phone recently? ") == 'yes':
if input("Did your drop your phone? ") == 'yes':
    if input("Did it become wet when you dropped it? ") == 'yes':
        print(sol4)

        else:  
        print(sol5)
else:  
if input("Has your phone ever been to slow?" ) == 'yes':
    print(sol5)
else:  
    if input("Have you got more than 30 apps?? ") == 'yes':
        print(solution3)
        else:

        if input("Is your phone older than two years?") == 'yes':
            print(no_warranty)
        else:  
            print(warranty)
    else: 
        print(warranty)

所以我的问题是,我如何完成此代码,以及如何将问题链接到更多问题?

谢谢!

无效的语法错误是因为您的代码没有正确缩进。 在python中,由于没有代码,因此必须缩进代码以使其正常工作; 在python中结束代码行:

例如对于嵌套代码块:

{
    Block 1
....{
    ....Block 2
        {
        ....Block 3
        }
    }
}

这里的4个点代表4个空格字符。

对于您的代码,您可以这样尝试:

if input("Did you buy your phone recently? ") == 'yes':
    if input("Did your drop your phone? ") == 'yes':
        if input("Did it become wet when you dropped it? ") == 'yes':
            print(sol4)
        else:
            print(sol5)
            ....

切记,使用python时,请始终正确缩进代码,否则它将引发无效的语法错误。

import time, webbrowser
while True:
    print('Hello, welcome to the phone broke hotline. Please follow the questions and only use 1 word answers.') 
    time.sleep(1.25)#program will stop for 1.25 seconds
    print('What phone model do you have?.')
    Q1=input().lower() #makes it all lower case
    if Q1[0]=='i' or Q1[0]=='s' or Q1[0]=='n' : 
        if Q1[1]=='p' or Q1[1]=='a' or Q1[1]=='o' :
            if Q1[2]=='h' or Q1[2]=='m' or Q1[2]=='k' :

                yes='y'
                y='yes'
                no='n'
                n='no'
                print('You have chosen ' + '' + Q1+ '' + '') 
                prob=input('Did your ' + '' + Q1+ '' + ' get wet?\n').lower() 
                if prob == yes or prob == y: 
                    print("place the phone in a ziplock bag with dry, uncooked rice for a couple of hours and if that doesn't work please contact the nearest phone repair shop") 
                    time.sleep(1) 
                    print() 
                    break
                elif prob == no or prob == n:
                    print('Did your screen crack?') 
                prob2=input().lower()  
                if prob2 == yes or prob2 == y:
                    print ('Go to this link to buy new phone parts.\n https://www.replacebase.co.uk/mobile-phone-parts/')  
                    webbrowser.open('https://www.replacebase.co.uk/mobile-phone-parts/')
                    time.sleep(1) 
                    print()
                    break
                elif prob2 == no or prob2 == n:
                    print('Is your ' + '' + Q1+ '' + '  unresponsive?') 
                prob3a=input().lower()  
                if prob3a == yes or prob3a == y:
                    prob3b=input('Is Your ' + '' + Q1+ '' + ' off?\n').lower() 
                    if prob3b == yes or prob3b == y:
                        print("Turn your " + '' + Q1+ '' + "  on and if it wont turn on put it on charge and if that doesn't work contact your nearest phone repair shop")
                        print()
                        break
                    elif prob3b == no or prob3b == n:
                        print('Go to your nearest phone repair shop') 
                        print()
                        break
                elif prob3a == no or prob3a == n:
                    print('Has your ' + '' + Q1+ '' + ' overheated')   
                prob4=input().lower() 
                if prob4 == yes or prob4 == y:
                    print('place in a cool area for a couple of hours')  
                    print()  
                    break
                elif prob4 == no or prob4 == n:
                    print('Your ' + '' + Q1+ '' + ' is fine. Thank You for using our services today.') 
                    print()  
                    print('         ...........') 
                    time.sleep(1) 
                    break

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM