2016-11-25 88 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()