3

我正在尝试使用 Genie 创建一个简单的 Hello World 程序,但我希望能够在终端上输入一些输入。我的目标是在 Genie 中重复以下 python 代码:

#!/usr/bin/env python
print 'Hello. I am a python program.'
name = raw_input("What is your name? ")
print "Hello there, " + name + "!"

到目前为止,我所做的是;

[indent=4]

uses System

init
    print "Hello. I am a python program."
    var name = Console.ReadLine("What is your name? ")
    print "Hello there, " + name + "!"

但是我得到了一些错误,可能是因为我对语言一无所知,这是错误:

hw.gs:4.5-4.10: error: The namespace name `System' could not be found
    System
    ^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
hw.gs:3.6-3.11: error: The namespace name `System' could not be found
uses System
     ^^^^^^
Compilation failed: 1 error(s), 0 warning(s)

我究竟做错了什么?

谢谢。

4

2 回答 2

2

如果您愿意,可以编写自己的raw_input函数:

[indent=4]

def raw_input (query : string? = null) : string?
    if (query != null)
        stdout.printf ("%s\n", query)
    return stdin.read_line ()

init
    print "Hello. I am a python program."
    var name = raw_input ("What's your name?")
    print "Hello there, " + name + "!"
于 2015-10-13T06:35:35.730 回答
2

BigOldTree 帮我提出了一个建议,这确实奏效了。以下是 Geanie 中代码的样子:

[indent=4]
init
    print "Hello. I am a python program."
    print "What's your name?"
    var name = stdin.read_line()
    print "Hello there, " + name + "!"

我不知道是否可以像在 python 中使用 raw_input() 一样向 stdin.read_line() 发送参数。很高兴知道这一点,我也不知道如何查找有关特定功能的信息以及如何导入它们。我来自 R,在那里我可以使用 ?function(),它会给我一些关于它的指导。Genie/Vala 上有类似的东西吗?

于 2015-10-02T06:18:11.637 回答