我有这个简单的python程序:
def GetNum (Text):
x = input("Input something: ")
while (x > 0):
x = input("Input something: ")
print x
Run Code Online (Sandbox Code Playgroud)
我想通过终端运行它,但是当我执行命令时:
python ./test.py
Run Code Online (Sandbox Code Playgroud)
或者如果我跑
python test.py
Run Code Online (Sandbox Code Playgroud)
没发生什么事。终端恢复正常,就好像没有执行过任何命令一样。
该文件位于 Documents/Python 下,我在运行命令时位于该目录中。我是否在这里遗漏了一些关于为什么这不起作用的信息?
您的程序不会输出任何内容,因为您从未调用过您的函数。
这将执行您期望的操作:
def GetNum():
x = int(input("Input something: "))
while (x > 0):
x = int(input("Input something: "))
print(x)
GetNum()
Run Code Online (Sandbox Code Playgroud)
我删除了函数参数Text,添加了对GetNum函数的调用,并为两个调用添加了从strto 的类型转换。intinput()
| 归档时间: |
|
| 查看次数: |
20237 次 |
| 最近记录: |