2016-11-25 71 views
1
import time 
def pini(): 
    pin1 = int(input("enter your pin please: ") 
    if pin1 == pin: 
      print("pin correct") 
      print("paying: £",amount) 
      print("opening connection...") 
      time.sleep(0.4) 
      print("contacting bank...") 
      time.sleep(1.0) 
      print("contacting bank...") 
      time.sleep(0.5) 
      print("contacting bank...") 
      time.sleep(0.2) 
      print("contacting bank...") 
      time.sleep(0.2) 
      print("transaction successful") 
    elif: 
      print("wrong pin, try again") 
      pini() 

print("Welcome to the bank") 
print("\n") 
pin = int(input("what is your pin: ") 

pay = "" 
while pay == "": 
    pay = input("press 'n' to make a payement: ").lower() 
    if pay == "n": 
      amount = int(input("please enter amount to pay: ") 
      print("please insert your card to pay" , "£",amount) 
      print("\n") 
      pini() 

這是我的代碼。運行我的代碼時出錯(語法無效)

運行時,出現「無效語法」錯誤,我正在使用Python/IDLE 3.4.2。 這只是一個學校項目的一個小程序,我遇到了一個錯誤。

我認爲可以縮進這是問題,但否則我不知道,任何幫助讚賞:)

+0

)在輸入中缺失 –

+0

在所有的'int(input(「))'調用中,您忘記關閉外部圓括號。 I.e'int(輸入(「請輸入你的PIN:」)' –

回答

1

我在你的代碼中放了一些註釋,如下所示。

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 

import time 
def pini(): 
    pin1 = int(input("enter your pin please: ")) # miss a right bracket ')' 
    if pin1 == pin:         # Be attention to your code indentation 
     print("pin correct") 
     print("paying: £",amount) 
     print("opening connection...") 
     time.sleep(0.4) 
     print("contacting bank...") 
     time.sleep(1.0) 
     print("contacting bank...") 
     time.sleep(0.5) 
     print("contacting bank...") 
     time.sleep(0.2) 
     print("contacting bank...") 
     time.sleep(0.2) 
     print("transaction successful") 
    else:  # it should be `else` instead of `elif` 
     print("wrong pin, try again") 
     pini() 

print("Welcome to the bank") 
print("\n") 
pin = int(input("what is your pin: ")) # Again, you miss the right bracket `)` 

pay = "" 

while pay == "": 
    pay = input("press 'n' to make a payement: ").lower() 
    if pay == "n": 
     amount = int(input("please enter amount to pay: ")) # Same problem `)` 
     print("please insert your card to pay" , "£",amount) 
     print("\n") 
     pini()