简体   繁体   中英

Troubleshooting Program in Python. How to link Qs?

I am here to ask another question about the code I am working on. I keep getting invalid syntax error. I asked a similar question on another account and someone answered the question and gave me a code. I edited it but i cannot seem to work it out. My project is to make a troubleshooting program for a mobile company. At the moment this is my code:

CODE:

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)

So my question is, how can i complete this code and how can i link questions to more questions?

Thanks!

Invalid Syntax error is because your code is not indented properly. In python you have to indent the code the right way to make it work since there is no ; in python to end the code line:

eg for nested code blocks:

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

Here the 4 dots represent 4 space characters.

for your code you can try like this:

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)
            ....

Always remember, while using python always proprly indent you code otherwise it will throw invalid syntax error.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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