简体   繁体   中英

Unclear Syntax Error Python

I'm getting an error and I'm not quite sure what the problem is. Here is my code:

from random import *
gen = (randint(1,50))
#matt = (randint(1,28))
ex = (randint(1,40)) 
#lev = (randint(1,27))

book = raw_input("What book do you want to read from today?     ").lower().strip('.')
x = "Your Random Chapter From " + book.upper() + " is Chapter "

#Genesis
if book == 'genesis':
    print x + str(gen)
    pass
elif book == 'gen':
    print x + str(gen)
    pass

#Exodus
elif book == "exodus":
    print x + (str(ex)
    pass
elif book == "ex"
    print x + (str(ex))
    pass

The current error I'm gettin is a syntax issue on line 21 "pass"

C:\Users\\#####\Desktop\Python\UnfinishedProjects>RandomChapter.py
  File "C:\Users\\#####\Desktop\Python\UnfinishedProjects\RandomChapter.py",     line 21
    pass
       ^
SyntaxError: invalid syntax

I am almost certain there are more issues but this is the one that is giving me problems now. If you see some other issue please tell me about that to. Thanks!

You just missed a bracket at the end of line 20; also line 22 is missing a colon. However, you don't actually need the pass in any of the if statements. In any case, the code could be made more compact by replacing line 10 onward with:

#Genesis
if "gen" in book:
    print x + str(gen)

#Exodus
elif "ex" in book:
    print x + (str(ex)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM