如何在Python中链接

时间:2015-01-10 16:44:14

标签: python python-3.x linker

我刚开始学习Python。

placemarker = 1
while True:
    print ("Welcome")
    command = input ("Enter command: ")
    if command == register:
        placemarker = 20

if placemarker == 20:
    registerMe = input ("What is your name? ")

当我将注册输入输入时,我试图链接到地标20区域。我怎么能实现这个目标?谢谢,我只是一个初学者。 :)

2 个答案:

答案 0 :(得分:0)

placemarker = 1
while True:
    print ("Welcome")
    command = input ("Enter command: ")
    if command == "register": #String variable here
        placemarker = 20

if placemarker == 20:
    registerMe = input ("What is your name? ")

像这样更改它,你应该告诉Python它是一个字符串,因为input将变量存储为字符串。你也可以这样写清楚 - 比你的代码清楚;

while True:
    print ("Welcome")
    command = input ("Enter command: ")
    if command == "register": #String variable here
        registerMe = input ("What is your name? ")
        print (registerMe) #print or do whatever you want on here
        break   

答案 1 :(得分:0)

方法input()会返回String,因此在if语句中您必须将register字词更改为"register",因为变量{{1将是一个字符串:因此if语句在command之后寻找一个字符串。 希望这有助于