如何解决python中的“注释非法目标”错误?

时间:2019-11-23 06:43:42

标签: 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()

2 个答案:

答案 0 :(得分:1)

从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""")

答案 1 :(得分:0)

如果在代码行的末尾不应该有“:”,也会出现此错误。 :)

如果名称 =='主要”: write_sequence(filename ='C:\ Python \ File_IO \ recaman.txt',num = 0)

如果是这样,则会显示错误。如果看起来要采取一些措施,我习惯将其放在行尾。 如果名称 =='主要': write_sequence(filename ='C:\ Python \ File_IO \ recaman.txt',num = 0)