Rob*_*ood 2 python syntax if-statement
这是我的代码:
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..."
Run Code Online (Sandbox Code Playgroud)
这是来自终端的确切错误消息:
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]
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个问题吗?我是一名初学者Python编码器,我正在编写一个学校项目的"轻微互动自传".
第二组应该是a elif,最后一组是你的else情况,所有这些都应该==用于相等比较,而不是=变量赋值:
# Define these variables *before* you use them...
# Variables - Chapters
chapter_one = "text here..."
chapter_two = "text here..."
chapter_three = "text here..."
if chapter == "Chapter 1":
print "Chapter 1"
print chapter_one
# This one should be an elif
elif chapter == "Chapter 2":
print "Chapter 2"
print chapter_two
elif chapter == "Chapter 3":
print "Chapter 3"
print chapter_three
# And the last one is an else
else:
chapters = raw_input("Please type either 'Chapter 1', 'Chapter 2', or 'Chapter 3': ")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5482 次 |
| 最近记录: |