简体   繁体   中英

Console opens then immediately closes, but code checkst out (Python, Sublime)

Hi I'm relatively new to coding and I don't know why this code isn't working

gender = input("What is your gender(m/f)?")
if gender.upper() == M:
    throw = paper
elif gender.upper() == F:
    throw = rock
else:
    print("issue")
print throw

Try :

gender = input("What is your gender(m/f)?")
if gender.upper() == "M":
    throw = "paper"
elif gender.upper() == "F":
    throw = "rock"
else:
    print("issue")
    exit() # terminate here , because name 'throw' is not defined.
print (throw)

Which editor/runtime are you using? You should be able to configure keeping the console open when your program exits so you can see any errors.

In your specific case it looks like you're using Python 3, and you need to surround the print argument with parentheses here too:

print(throw)

As well as using quotes around "M" and "F" to signify that they're strings.

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