python - 如何修复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()
解决方案
从第 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""")
推荐阅读
- java - Android FirebaseML - 本地模型未注册:
- python - 错误:尝试替换为 backslah 时,位置 0 处的错误转义(模式结束)
- python - 如何使用过滤功能识别特殊字符的索引
- java - 如何在 AWS Device Farm 中运行 maven 命令
- android - simpli 从 esspresso android 中的自定义视图获取视图
- amazon-web-services - Docker swarm 工作节点无法为其托管的 nginx 服务提供服务
- spring-boot - 无法为 Spring Boot 2 应用程序中的拦截器添加配置 WebMvcConfigurer
- javascript - react.js 根块的不同内容
- json - 无法在 shell 脚本中使用 sed 提取 json 文件的特定值
- python - 如何仅将列表中第一个单词的首字母大写