Python raw_input()语法错误

时间:2016-05-02 14:02:28

标签: python

每当我运行这段代码时,它会一直指向raw_input()中的“t”并说SyntaxError: invalid syntax.我做错了什么?

if key == True:
                when raw_input().lower() = "get":
                print "Sorry, there is nothing more to get here."

2 个答案:

答案 0 :(得分:0)

正确的语法是

foreach ($record as $doc)
{
    $groupIds[] = $doc['groupId'];
}

$gpids = "'".implode("','",array_unique($groupIds))."'";
$collection5 = $db->chat;
$cursor = $collection5->find(array('groupId' => array('$in' => array($gpids))));

foreach($cursor as $res)
{
     print_r($res);
}

时没有关键字

答案 1 :(得分:0)

我知道你的意思,但你正在编写某种伪代码。试试这个:

if key:
    while True:
        reply = raw_input().lower()
        if reply == "get":
            print "Sorry, there is nothing more to get here."
            break
        # else ...

我放弃了== True,这只是个人偏好,如果您愿意,使用它没有任何问题。

我将用户输入的返回字符串存储到reply,因为大概您将处理用户的回复。我也把它放在一个循环中,你暗示使用单词when而不是ifbreak立即退出循环。

相关问题