如何解决无法将代码格式化为所需的输出
我正在尝试以以下格式打印代码,但是似乎没有任何效果。有人可以指出代码或逻辑中的错误吗?
所需格式: We have got only 3 oranges and only 1 apple
代码:
excess = {"apple": 5,"orange": 6}
s = ""
for k,v in excess.items():
n = 1
if n == 0:
s = "We have got only {} {} ".format(v,k)
elif n > 1:
s += "and {} {}".format(v,k)
n += 1
print(bill,s)
输出
We have only 6 orange
解决方法
您需要在循环外部定义return (
<div className="pg-driver-view">
<div className="video-container">
{this.renderLoading()}
<video style={{ visibility }} controls onCanPlay={e => this.onCanPlay(e)}>
Video playback is not supported by your browser.
<source src={filePath} type={`video/${fileType}`} />
<track src="test_captions_en.vtt" kind="captions" srcLang="en" label="hello_english_captions" />
</video>
</div>
</div>
);
,并用n
(或n>1
)替换n>0
条件
else
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。