简体   繁体   中英

Python only running first line, not sure what I'm missing

I just started learning today and I'm writing a simple block. It asks for the name and then stops. This is what I get http://imgur.com/KTwQz6G but only if I paste from IDLE. If I copy it from this site it seems to work. Maybe it's because I'm using an old version of IDLE to write it?

name = raw_input("What is your name? ")

color = raw_input("What is your favorite color? ")

print "Well, Hello %s. I was hoping you would pick dark brown, 
but %s is cool too." % (name, color)

The program will not ask all the questions at once. You need to enter a name when you are prompted to do so by the raw_input method and then the same for color. Example:

>>>python file.py
What is your name? somename               #you type somename and press enter
What is your favorite color? somecolor    #you type somecolor and press enter
Well, Hello somename. I was hoping you would pick dark brown, but somecolor is cool too.

It asks for the name. The user has to type it in the prompt then press enter in order for the code to continue executing. That's what raw_input does.

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