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

时间:2015-12-03 13:43:56

标签: python

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

CODE:

angular.module('myapp')
  .controller('LoginCtrl', function ($scope, Auth, $location, $window) {
    $scope.user = {};
    $scope.errors = {};

    $scope.login = function(form) {
      $scope.submitted = true;

      if(form.$valid) {
        Auth.login({
          email: $scope.user.email,
          password: $scope.user.password
        })
        .then( function() {
          // Logged in, redirect to home
          $location.path('/main');
        })
        .catch( function(err) {
          $scope.errors.other = err.message;
        });
      }
    };

    $scope.loginOauth = function(provider) {
      $window.location.href = '/auth/' + provider;
    };
  });

所以我的问题是,如何完成此代码以及如何将问题与更多问题相关联?

谢谢!

2 个答案:

答案 0 :(得分:1)

无效语法错误是因为您的代码没有正确缩进。 在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总是支持缩进代码,否则会抛出无效的语法错误。

答案 1 :(得分:-1)

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