首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

怎样用python数星星?

Lately, I've been, I've been losing sleep

Dreaming about the things that we could be

But baby, I've been, I've been playing hard,

Sitting, no more counting dollars

We'll be counting stars, yeah we'll be counting stars

I see this life like a swinging vine

Swing my heart across the line

And my face is flashing signs

Seek it out and you shall find

Oh, but I'm not that old

Young, but I'm not that bold

I don't think the world is sold

I'm just doing what we're told

I feel something so right

Doing the wrong thing

I feel something so wrong

Doing the right thing

I could lie, could lie, could lie

Everything that kills me makes me feel alive

今天老西儿用python数星星,一开始数了21颗,后来越数越多,越数越多……从1数到了1000000!自己数,手指头不够用啊!最后从1加到1000000,一共是多少呢?哎呀头痛!

作业来源:《Python编程:从入门到实践》

图源:马蜂窝

4-3 21 stars

for value in range(1,21):

print(value)

图源:堆糖

4-4 millionaire

stars = list(range(1,1000001))

for value in stars:

print(value)

图源:astroarts

4-5 counting stars

print(min(stars))

print(max(stars))

print(sum(stars))

input()

运行效果:

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20180907G1ZUS800?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券