簡體   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