python if else elif经典例题和答案_使用我的If,Else和Elif语句(Python)的“语法错误”...

一名Python初学者在创建一个学校的交互式自传项目时遇到了语法错误。代码试图根据用户输入显示不同章节的内容,但在`else`语句中出现了语法错误。错误发生在尝试将`chapter`赋值为'Chapter2'时,导致程序无法正常运行。解决方案可能涉及修正`else`块的语法结构。
摘要由CSDN通过智能技术生成

这是我的代码:

print "Hello, and welcome to the Slightly Interactive Autobiography of Robbie Wood."

print "Lets get started, shall we? What chapter would you like to read first?"

chapter = raw_input("Please type either 'Chapter 1', 'Chapter 2' or 'Chapter 3': ")

if chapter = "Chapter 1":

print "Chapter 1"

print chapter_one

else chapter = "Chapter 2":

print "Chapter 2"

print chapter_two

elif chapter = "Chapter 3":

print "Chapter 3"

print chapter_three

elif:

chapters = raw_input("Please type either 'Chapter 1', 'Chapter 2', or 'Chapter 3': ")

# Variables - Chapters

chapter_one = "text here..."

chapter_two = "text here..."

chapter_three = "text here..."这里是终端的确切错误信息:

Last login: Fri Sep 7 17:22:59 on ttys000

Robbies-MacBook-Pro:~ robbiewood$ /var/folders/y6/kx37qgbs34124ztdgb4tphs00000gn/T/Cleanup\ At\ Startup/autobiography-368756862.498.py.command ; exit;

File "/private/var/folders/y6/kx37qgbs34124ztdgb4tphs00000gn/T/Cleanup At Startup/autobiography-368756862.497.py", line 9

else chapter = "Chapter 2":

^

SyntaxError: invalid syntax

logout

[Process completed]有人能帮我解决这个问题吗?我是一名初学者的Python编码员,我正在为一个学校项目编写一个“稍微交互式的自传”。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值