- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我已经在互联网上搜索并尝试了代码的变体,但我只是不明白为什么当我在 Udacity 计算机科学入门的第 2 课中研究 PS 2 时,结果之间的输出为“无” .
这是 PS 和我当前的状态:
# Define a procedure, stamps, which takes as its input a positive integer in
# pence and returns the number of 5p, 2p and 1p stamps (p is pence) required
# to make up that value. The return value should be a tuple of three numbers
# (that is, your return statement should be followed by the number of 5p,
# the number of 2p, and the nuber of 1p stamps).
#
# Your answer should use as few total stamps as possible by first using as
# many 5p stamps as possible, then 2 pence stamps and finally 1p stamps as
# needed to make up the total.
#
def stamps(n):
if n > 0:
five = n / 5
two = n % 5 / 2
one = n % 5 % 2
print (five, two, one)
else:
print (0, 0, 0)
print stamps(8)
#>>> (1, 1, 1) # one 5p stamp, one 2p stamp and one 1p stamp
print stamps(5)
#>>> (1, 0, 0) # one 5p stamp, no 2p stamps and no 1p stamps
print stamps(29)
#>>> (5, 2, 0) # five 5p stamps, two 2p stamps and no 1p stamps
print stamps(0)
#>>> (0, 0, 0) # no 5p stamps, no 2p stamps and no 1p stamps
产生输出:
(1, 1, 1)
None
(1, 0, 0)
None
(5, 2, 0)
None
(0, 0, 0)
None
谁能解释一下“无”从何而来?
最佳答案
您正在调用打印结果的函数,然后打印该函数的返回值,即None
。
您应该选择一种显示数据的方法。要么只在函数内部打印:
def stamps(n):
if n > 0:
five = n / 5
two = n % 5 / 2
one = n % 5 % 2
print five, two, one
else:
print 0, 0, 0
stamps(8)
stamps(5)
stamps(29)
stamps(0)
或者使用return
:
def stamps(n):
if n > 0:
five = n / 5
two = n % 5 / 2
one = n % 5 % 2
return five, two, one
else:
return 0, 0, 0
print stamps(8)
print stamps(5)
print stamps(29)
print stamps(0)
关于python - Udacity 深入计算机科学 (Python) 第 2 课 PS 印章 - 输出包括 "None",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40827161/
我在 tomcat 8.0.24 上运行 Atlassian Bitbucket,在 Ubuntu 14.04.5 LTS 上运行 Java 1.8.0 31-b13(64 位),内核 3.13.0-
docker命令reference for ps提到 docker ps -a docker ps --all 命令显示所有容器的列表。 在docker上工作时,我错误地使用了以下命令 docker
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
docker ps 不让我知道容器本身的 pid。在主机上运行的 docker ps 和 ps 的输出之间进行命令字符串匹配并不是万无一失的,因为我可以在主机上运行相同的命令。 有没有人有确定的方法将
如何通过命令“ps”或“ps -ef”知道进程是在后台运行还是在前台运行? 我首先想到的是,当我输入 ps -ef 时,有一个名为 TTY 的部分。 当我查看 TTY 列表时,大多数都是“?” (问号
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我正在使用带有 3 个文件的 GUI 编写 PowerShell 脚本: window1.ps1 - 输入变量并启动start.vbs start.vbs - 启动window2.ps1 window
这似乎是一个愚蠢的问题,但我一直无法找到明确的答案。 This website指出破折号是可选的 ps aux 然而,ps aux有效但 ps -aux出现错误 no user named 'x' .
我有一个 bash 脚本 (ScreamDaemon.sh),在其中添加了检查它的示例是否已经运行的检查。 numscr=`ps aux | grep ScreamDaemon.sh | wc -l`
我需要解释一下 ps -ef 命令的四个字段(4 或 0),这个数字的含义谢谢你 root 27116 27112 4 15:25 pts/0 00:00:00 grep -qsRw -m1 moni
我刚开始学习 linux 命令,请帮助我找出 ps -ef 和 ps -ef | 之间的区别 | linux 中的 more 命令 最佳答案 与 ps -ef | more你管| ps 的输出至 mo
# ps | grep safe 14592 root 136m S /tmp/data/safe/safe 16210 root 1664 S grep safe
我有一个 bash 脚本 (ScreamDaemon.sh),在其中添加了检查它的示例是否已经运行的检查。 numscr=`ps aux | grep ScreamDaemon.sh | wc -l`
为什么 docker compose 创建的容器只能从 docker-compose ps 访问并且在杀死正在运行的容器后仍然存在? 最佳答案 不是。 docker ps只显示正在运行的容器,dock
我试图在 unix 框中找到所有正在运行的 java 进程。我很困惑 ps –ef|grep java 和 ps –ef|grep *.java 哪一个是正确的,确切的区别是什么? PS:两者都返回不
给定一个 pid 数组和代码: for i in ${listedPids[@]} do runningCheck="ps -u $USER | grep $i"
我的 PowerShell 配置文件 (CurrentUser.AllHosts) 中有两个脚本让我抓狂,因为它们在看似相同的控制台上给出了不同的结果。在 Powershell(提升版)上,脚本没有任
对于我正在创建的 python 脚本,我需要先获取进程的 PID(基于其名称),然后使用其 PID、持续时间从该进程获取,从下面的打印输出中,将是“00:00:00” root 5686
前言 大家好,我是 god23bin。欢迎来到《 一分钟学一个 Linux 命令 》系列, 每天只需一分钟,记住一个 Linux 命令不成问题 。今天要说的是 ps 命令。
我发现 ps aux 列出了当前正在运行的进程,我发现其他人提到了 ps auxwww .我想知道这是什么意思?或者它有什么作用? ps aux有什么区别和 ps auxwww ? 最佳答案 引用 m
我是一名优秀的程序员,十分优秀!