首页 > 解决方案 > 如何修复python中的错误“注解的非法目标”?

问题描述

我正在学习 Python,这个程序运行良好,但突然我从 : 在第 33 行到程序末尾出现了一条红线,错误为“注解的非法目标”。我该如何解决这个问题?

import turtle
import decimal
from decimal import Decimal
import sys
account_1_name = "John Smith"
account_1_balance = "67.58"
account_1_vault_balance = "200.00"
style = ('Calibri', 30)
password = input("What is your password?")
if password == "Cryptic":
    turtle.hideturtle()
    turtle.bgcolor("green")
    turtle.write("Access Granted.", font=style)
    turtle.done()
    prompt = input("""
    Welcome to Bank Network.

    Hello, %s
    Your balance is $%s
    Your savings account balance is $%s.

    type transfer to transfer money to savings section.      
    type deposit to deposit a check.""" % (account_1_name, account_1_balance , account_1_vault_balance))
    if prompt == "deposit":
            print("deposit system is down right now. Please try again later.")
            sys.exit(0)
    if prompt == "transfer":
        transfer_amount = input("How much do you want to transfer?")
        transfer_prompt = input("""
        are you sure you want to transfer money to your savings section?
        type cancel to cancel.
        type confirm to transfer"""
    if transfer_amount > account_1_balance:
        print("Not enough balance.")
    if transfer_amount < account_1_balance:
        print("Ok. Money transfered.")
        balance_post_transfer = Decimal(account_1_balance) - Decimal(transfer_amount)
        account_1_vault_balance_post_transfer = Decimal(account_1_vault_balance) + Decimal(transfer_amount)
        print("Your balance is now $%s and your savings account balance is $%s" % (balance_post_transfer, account_1_vault_balance_post_transfer))
if password != ("Cryptic"):
    turtle.hideturtle()
    print("access denied.")
    turtle.bgcolor("red")
    turtle.write("access denied.", font=style)
    turtle.done()

标签: python

解决方案


从第 29 行到第 32 行,您有:

transfer_prompt = input("""
    are you sure you want to transfer money to your savings section?
    type cancel to cancel.
    type confirm to transfer"""

你没有关闭输入。这就是你错误的原因。将这些行替换为:

transfer_prompt = input("""
    are you sure you want to transfer money to your savings section?
    type cancel to cancel.
    type confirm to transfer""")

推荐阅读