Python简介,第1章–算术和变量



Seated in his cubicle, Baldric tried to block out the buzz of busy clerks scattered about the office. The usual mix of apathy, grumpiness, and existential dread filled his thoughts, but something was tugging at the back of his mind. It felt vaguely like a sense of…hope. Almost as if there was finally a way out of this nightmare. Wait, there was something he dreamed about last night, some sort of…

在他的隔间eated,佩饰尝试把散落在办公室忙碌的职员的嗡嗡声。 冷漠,脾气暴躁和生存恐惧的平常组合充斥着他的思想,但他的脑海里却有些牵扯。 隐约感觉像是一种希望。 几乎仿佛终于摆脱了这场噩梦。 等等,昨晚他梦到了某件事,某种……

“Howdy doody Baldric! Working hard or hardly working? Hehehehehe.”

“你好,波德瑞克! 努力工作还是几乎没有工作? 呵呵呵呵呵。”

Baldric looked up to see a young male halfling laughing mechanically. It was Kevin, Baldric’s supervisor. As usual he was seated on a platform borne aloft by several interns.

鲍德瑞克抬起头,看到一个年轻的男性半身人机械地笑着。 是鲍德瑞克(Baldric)的主管凯文(Kevin)。 像往常一样,他坐在几个实习生高举的平台上。

“Any-hoo, just wanted to pop in and see if you’re staying above water. With everything coming down the pipeline I think we need to have a little pow wow later this afternoon to make sure all our ducks are in a row. From our standpoint, we’re really gonna need to coordinate if we don’t want to drop the ball.”

任何人,只是想跳进去看看你是否停留在水面之上。 随着一切的进行,我想我们需要在今天下午晚些时候做一点哇,以确保我们所有的鸭子都排成一排。 从我们的角度来看,如果我们不想丢球,我们真的需要协调。”

Baldric looked into Kevin’s dull gray eyes. They always looked the same regardless of the emotion he was exhibiting, cold on the outside yet burning with a searing fervor deep within.

鲍德瑞克看着凯文呆滞的灰色眼睛。 无论他表现出什么情感,他们总是看起来一样,外面很冷,但内心深处灼热。

“Yes Kevin, I’ll have the inventory calculations done on time, no problems…”

“是的,凯文,我会按时完成库存计算,没有问题……”

“Great, well, you know I have an open door policy if you ever need to drop by and let me know where your head’s at. With Steve having to take a little trip to HR, we’re all gonna be playing a little catch up.” With a couple quick claps, the interns lifted the platform back up. “Keep me in the loop, and don’t forget, Busyness is Progress!” said Kevin with a big grin as he was carried away.

“太好了,好吧,如果您需要路过并告诉我您的头向何处,您知道我有开放政策。 由于史蒂夫(Steve)必须走一点人力资源,我们都会变得有些追赶。” 经过几次快速的掌声,实习生将平台抬起。 “让我保持循环,别忘了,忙碌是进步!” 凯文被带走时咧嘴一笑。

“Busyness is Progress,” replied Baldric, cringing at the Empire’s slogan. Poor Steve. He had been the last person whose presence didn’t make Baldric physically ill. Few things in this world were worse than a trip to Humanoid Resources. But in spite of it all, he was quite pleased with himself. He was almost finished with the day’s work, and it wasn’t even midmorning yet!

“忙碌就是进步,”鲍德里克回答说,对帝国的口号感到畏缩。 可怜的史蒂夫。 他是最后一位没有让鲍德瑞克(Baldric)身体不适的人。 在这个世界上,没有什么事情比人形资源之旅还差。 但是尽管如此,他还是对自己很满意。 他一天的工作快要完成了,还没到早上呢!

Since waking up, the otherwise ordinary dwarf had found he had a strange ability to weave patterns of threads. Not actual threads, as no one else seemed able to see them, but some sort of green immaterial threads composed of 0’s and 1’s that were seemingly conjured from his mind. To weave the threads he needed only to concentrate on a calculation, and when the pattern was finished it collapsed into that calculation’s result. Amazingly, these patterns could perform once-tedious arithmetical computations in the blink of an eye. Was he finally losing his mind? Maybe this place had gotten to him more than he realized.

醒来之后,原本普通的小矮人发现他具有编织线型的奇特能力。 不是真正的线程,就像其他人似乎看不到的那样,而是某种由0和1组成的绿色非物质线程,似乎从他的脑海中浮现出来。 为了编织线程,他只需要专注于计算,当模式完成时,它就会折叠到该计算的结果中。 令人惊讶的是,这些模式可以在眨眼间执行繁琐的算术运算。 他终于失去理智了吗? 也许这个地方对他来说意义非凡。

Sighing, Baldric turned back to the inventory calculations he had been working on and began again to weave his patterns. “Let’s see, a stock of 81 whips in one HR storeroom, 76 whips in another, for a total of…

叹了口气,Baldric回到他一直在进行的库存计算,并再次开始编织他的图案。 “让我们看看,在一个HR储藏室中存有81鞭子,在另一个HR储藏室中存有76鞭子,总共…

>>> 81 + 76
157

…157 available whips,” Baldric muttered to himself, noting the result of his mystical calculation in the ledger. He didn’t even really have to think about the patterns he was weaving, he somehow intuitively knew what to do.

……157条可用的鞭子,”鲍德里克喃喃自言,指出他在账本中神秘计算的结果。 他甚至不需要真正考虑自己编织的图案,而是凭直觉就知道该怎么做。

“And here we have corpse shroud counts. 434 in the first crate, 286 in the second, then 342, 260, 419, and finally 239, for a total of…

“在这里,我们有尸体裹尸布的数量。 第一个板条箱中有434个,第二个板条箱中有286个,然后是342个,260个,419个,最后是239个,总共…

>>> 434 + 286 + 342 + 260 + 419 + 239
1980

…1,980 shrouds. Seems a bit short.” He checked his calculations by hand and found that yet again his weaving was correct. Somehow he had learned this curious new way of doing arithmetic since falling asleep last night. Perhaps in a dream? Well, he would have to keep quiet about that. Sleeping was permitted, if just barely, but dreaming? Anyone caught dreaming by the Empire soon went the way of Steve.

…1,980套。 似乎有点矮。” 他用手检查了一下计算结果,发现织法仍然是正确的。 自昨晚入睡以来,他以某种方式学会了这种奇怪的算术新方法。 也许在梦中? 好吧,他将不得不对此保持沉默。 即使只是勉强睡觉,也可以做梦吗? 帝国梦caught以求的人很快就走上了史蒂夫的道路。

“What’s next…ah, impaling stakes. In HR’s warehouse, the stakes are stored upright in a grid, with 122 to a row and 87 to a column. With 122 rows by 87 columns, we must have…

“接下来是什么……啊,刺入赌注。 在HR的仓库中,木桩垂直放置在网格中,其中122列排成一列,而87列排成一列。 122行乘87列,我们必须有……

# variables can be used to store numbers

>>> rows = 122
>>> columns = 87
>>> rows * columns
10614

…10,614 of them. Impaling stake supplies seem to be sufficient. At least until mid-year reviews.

…其中10,614 刺穿股份供应似乎就足够了。 至少直到年中审查。

Let’s see, the next section of calculations is on employees under “extended review”. Humanoid Resources has 3 cell blocks, where Cell Block A has 600 cells, B has 800, and C has 1,000. With all the cell blocks full as of last week, there must have been…

让我们看看,下一部分计算是针对“扩展审核”下的员工。 人形资源有3个单元格,其中单元格A有600个单元格,B有800个单元格,C有1,000个单元格。 截至上周,所有单元格已满,肯定有……

# variables can also be assigned expressions
# these expressions automatically evaluate to a single number

>>> population_last_week = 600 + 800 + 1000
>>> population_last_week
2400

…2,400 employees there. But with 97 firings, 52 other deaths, 0 escapes, and 15 new arrivals, that total will change. We now have…

…那里有2,400名员工。 但是,随着97次射击,52次其他死亡,0次逃逸和15次新来者的出现,总数将发生变化。 我们现在有...

# variables can help make calculations more readable
# parentheses can help clarify or change the order of operations

>>> firings = 97
>>> other_deaths = 52
>>> escapes = 0
>>> new_arrivals = 15
>>> current_population = population_last_week - (firings + other_deaths + escapes) + new_arrivals
>>> current_population
2266

…2,266 remaining employees under extended review.” Baldric paused a moment to shudder at the thought of being sent to HR. Whereas employees (there were no longer citizens, only full-time employees) in good standing were only mandated to have 5 staff meetings a week, inmates were forced to have 10 every day. Worse, rumor had it HR was remodeling soon and planned to convert the cell blocks to an open floor plan. Surely even HR couldn’t be that cruel.

…剩余2266名员工正在接受进一步审核。” Baldric想到被送到HR时,停了片刻。 信誉良好的员工(不再有公民,只有全职员工)仅被要求每周召开5次员工会议,而囚犯则被迫每天召开10次会议。 更糟糕的是,有传言称人力资源部即将进行改建,并计划将单元转换为开放式平面图。 当然,甚至人力资源也不会那么残酷。

“And now for some military sums. They want to know how many arrows per archer are stockpiled in the local barracks. Well, with an estimated 7,263,180 arrows divided among 127,060 trained archers, we have…

“现在还有一些军事费用。 他们想知道每个弓箭手在当地军营中储存了多少支箭。 好吧,据估计,有7,263,180支箭分配给127,060名训练有素的弓箭手,我们有……

>>> arrows = 7263180
>>> archers = 127060
>>> arrows_per_archer = arrows / archers
>>> print(arrows_per_archer)
57.16338737604281

# print() is used above to show a variable's value
# in interactive mode you can also enter a variable's name to see its value (as done previously)
# if you are using script mode, however, you must use print() for a value to be displayed
# see here for more details https://datarebellion.com/blog/coding-in-interactive-mode-vs-script-mode/

…a little over 57 arrows per archer.

…每个弓箭手多出57支箭。

And here it says the Empire has 38 crates of newly-manufactured swords. If each crate is a cube with 2 meter-long sides, and 160 swords fit in one cubic meter, then in total we have…

这里说帝国拥有38箱新制造的剑。 如果每个板条箱是一个具有2米长的边的立方体,并且160把剑装在一立方米中,那么总共就有……

>>> number_of_crates = 38
>>> crate_volume = 2**3 # a double asterisk is used for exponents
>>> swords_per_cubic_meter = 160
>>> swords = number_of_crates * crate_volume * swords_per_cubic_meter
>>> print(swords)
48640

…48,640 swords.” Baldric could feel a sort of difference between his last two calculations. It was as if the results of those calculations were of different…types. Well, both were numbers, but one was a whole number with no decimal point and the other had a decimal point with numbers after it. Relying on intuition, Baldric began to weave something he thought might help explain the difference.

…48,640剑。” 鲍德瑞克可能会感到他的最后两次计算之间有些不同。 这些计算的结果好像是不同的……类型。 嗯,两个都是数字,但是一个是没有小数点的整数,另一个是带小数点的数字。 依靠直觉,Baldric开始编织一些他认为可能有助于解释差异的东西。

# what's different about arrows_per_archer compared to swords?
# they are different "types" of things

>>> type(arrows_per_archer)
<class 'float'>

>>> type(swords)
<class 'int'>

# a float is a number with a decimal point
# int is short for integer, a number which doesn't have a decimal point

# you can convert an integer to a float like so
>>> float(5)
5.0

# and you can also convert a float to an integer
>>> int(5.0)
5

>>> int(5.8462)
5

“Hmm, I knew they felt different. I wonder…”

“嗯,我知道他们有不同的感觉。 我想知道…”

As Baldric was muttering to himself, Kevin floated back over to Baldric’s cubicle. “Baldric, hey, you keeping busy? Let’s touch base for a second. I know you’ve got a lot on your plate, but I want to try and take care of some of the low hanging fruit before we get too swamped. Here’s a request I want you to go ahead and take the lead on. A Senior Manager needs a book from the library.” Kevin handed Baldric a note. “Let’s circle back once you knock this out. Thanks for jumping on this champ!”

当鲍德瑞克自言自语时,凯文飘回了鲍德瑞克的小房间。 “鲍尔德里克,嘿,你忙吗? 让我们稍等一下。 我知道您的菜板上有很多东西,但我想尝试一下,以免一些垂头丧气的水果在我们陷入困境之前得到照顾。 这是我的要求,希望您继续前进。 高级经理需要图书馆的书。” 凯文(Kevin)递给鲍德里克(Baldric)一张纸条。 “一旦你把它敲出来,就让我们转回去。 感谢您跳入这个冠军!”

Adjusting his glasses, Baldric read the note. The book was titled, That’s No Wyvern, That’s My Wife! Learning to Live with a Permanently Polymorphed Spouse. “At least I’ll get out of this god-forsaken office for a bit,” Baldric quietly grumbled to himself once Kevin was gone. He shuffled outside, passing several vacant-looking clerks engaged in conversation.

鲍德里克调整眼镜,读了笔记。 这本书的标题是,那不是飞龙,那是我的妻子! 学习与永久多态的配偶生活。 “至少我会离开这个被上帝抛弃的办公室一点,”凯文离去后,鲍德瑞克对自己安静地抱怨。 他在外面拖着脚步,经过了几位空空的店员进行交谈。

“So I told Bob that what we really need is to all get on the same page and start implementing best practices, because at the end of the day there’s no point in reinventing the wheel.”

“所以我告诉鲍勃,我们真正需要的是所有人都坐在同一页上,并开始实施最佳实践,因为到最后,再也没有必要重新发明轮子了。”

“Exactly, we don’t have the bandwidth to be constantly shifting gears, and from our standpoint…”

“确实,从我们的角度来看,我们没有足够的带宽来不断地换档……”

It was a short walk to the library, the streets empty aside from a couple of half-elves lounging about, a dangerous thing to be doing during work hours. Fewer people seemed to be going outside recently, but this was the emptiest Baldric had seen it at this time of day.

距图书馆仅几步之遥,街道上空无一人,有几个半精灵闲逛,这是在工作时间要做的一件危险的事情。 最近似乎很少有人去户外活动,但这是Baldric在一天中这个时间所见过的最空虚的地方。

The library Baldric was headed to was quite different from the ones he remembered as a kid. There was only one library now, and of course most of the books were about work, such as Impress Your Boss and Never Leave the Office Again!, The 7 Habits of Highly Obedient People, and 50 Great Gossip Techniques That Will Drive Your Coworkers Crazy! But these were available to everyone, and Baldric knew his target would be in the Privileged section where they kept the books for higher-ups’ eyes only.

Baldric前往的图书馆与他小时候记得的图书馆大不相同。 现在只有一个图书馆,当然大多数书籍都是关于工作的,例如打动老板,再也不要离开办公室!,高度听话的7种习惯以及50种使同事疯狂的八卦技巧。 ! 但是这些内容可供所有人使用,而且鲍德瑞克(Baldric)知道他的目标将在“特权”部分,在那里他们只保留书本以供更高层人士观看。

Upon arriving and showing his request to the section’s guard, Baldric quickly located the requested book. But it was a larger one next to it that caught his eye. He could tell this other book was old. Not in bad shape, but it had a sense of age about it. Leatherbound, no title. He casually flipped through it. Page after page was covered in a small, neat script occasionally punctuated by inscrutable drawings and schematics. He turned back to the start and began to read. It was talking about magic!

到达并向部门警卫显示要求时,BaldricSwift找到了所要求的书。 但是旁边有一个更大的吸引了他的注意。 他可以说这另一本书是旧的。 虽然状态不佳,但它具有一定的年龄感。 皮装,无标题。 他随便翻阅了一下。 一页又一页地覆盖着一个小的,整洁的脚本,偶尔会被难以理解的图纸和示意图打断。 他转头开始阅读。 这是在谈论魔术!

“The Multiverse is composed of five fundamental elements: Wind, Water, Earth, Fire, and Logic. The weaving of these elements comprises the art and science of Magic.” Much of it was even less intelligible, such as, “The Primordial Weaver, the Prime Loop, the Great Serpent, is that which gives rise to reality”, and, “The Multiverse is comprised of Magic, yet its most fundamental building blocks are not elemental threads, but…” Baldric became entranced in the scribblings, and after a few minutes it even started to make sense. Wait, there was a section on arithmetic. “The weaving of sums and products and the like is the most basic use of the Magic of Logic.”

“多元宇宙由五个基本元素组成:风,水,地球,火和逻辑。 这些元素的编织包括魔术的艺术和科学。” 它的大部分甚至更难以理解,例如,“原始织布工,Prime Loop,大蛇是产生现实的事物”,以及“ Multiverse由魔术组成,但其最基本的构成部分是而不是基本的线程,但是……” Baldric陷入混乱之中,几分钟后,它甚至变得有意义了。 等一下,有一节关于算术。 “总和和乘积之类的编织是逻辑魔术最基本的用途。”

Baldric’s jaw dropped. “Magic? I know how to use Magic!? I guess that explains those threads that do math I’ve been weaving. Braid my beard, this is…” His excitement quickly subsided after remembering what happened to Magic users. If someone used Magic in public, they skipped HR altogether and were sentenced to an immediate Firing. Burning at the stake, as it was once called. So anyone with any sense kept their Magical abilities secret. But inevitably they disappeared anyways. Baldric had known a few. At work one day, their cubicle cleared out the next. Baldric could’ve sworn he’d later seen one of them wearing the garb of Management as they passed in the hall several months back, but she didn’t appear to recognize Baldric.

鲍德里克的下巴掉了下来。 “魔法? 我知道如何使用魔术!! 我想这解释了我一直在编织的那些数学线程。 把我的胡须编成辫子,这是……”他回想起Magic用户所发生的事情后,他的激动很快消失了。 如果有人在公共场合使用Magic,他们将完全跳过HR,并被判立即解雇。 曾经被称为“危在旦夕”。 因此,任何有理智的人都将自己的魔法能力保密。 但是他们还是不可避免地消失了。 鲍德里克知道一些。 在一天的工作中,隔间清理了隔间。 鲍德瑞克可能发誓,他后来看到他们中的一个穿着管理服装,几个月前,当他们经过大厅时,但她似乎并没有认出鲍德瑞克。

Suppressing a growing sense of dread, he continued reading and found a section on arithmetic. It was talking about some sort of arithmetic he wasn’t familiar with. “Beyond the usual operators for addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (**), there is also %, which allows one to perform clock arithmetic. Meditate on the fact that no matter how many hours pass on the face of a clock, it always gives an hour between 1 and 12. If one starts at midnight and 13 hours pass, the clock reads 1. If instead 25 hours pass from midnight, the clock still reads 1. Such Magic is often of use to skilled Logic users.” Baldric paused to try out clock arithmetic for himself.

他抑制了日益增长的恐惧感,继续阅读并找到了有关算术的部分。 谈论的是他不熟悉的某种算术。 除了用于加法(+),减法(-),乘法(*),除法(/)和乘幂(**)的常用运算符之外,还有%,它允许人们执行时钟算法。 考虑这样一个事实:无论时钟经过多少小时,它始终会给出1到12之间的一个小时。如果从午夜开始,经过13个小时,时钟将显示1。如果相反,从午夜过去了25个小时,时钟仍显示为1。此类Magic通常对熟练的Logic用户有用。 鲍德里克停下来尝试自己的时钟算法。

# 13 hours pass on a 12 hour clock
>>> 13 % 12
1

# 25 hours pass on a 12 hour clock
>>> 25 % 12
1

# 1 hour passes on a 12 hour clock
>>> 1 % 12
1

# 8 hours pass on a 6 hour clock
>>> 8 % 6
2

# 1,000,000 hours pass on a 2 hour clock
>>> (10**6) % 2
0 

# 0 indicates the "noon", or starting, position on a clock

“Interesting, I think there’s some work where this will come in handy. And I don’t see how anyone will find out. I’ve apparently been weaving Magic all morning long and no one’s said a word. Hmm, I wonder what else I can do with Logic, not to mention with Wind and Fire and…” Thoroughly absorbed in the book, Baldric read page after page as time faded away.

“有趣的是,我认为有些工作会派上用场。 而且我看不出有人会发现。 我显然整个上午都在编织Magic,但没人说一句话。 嗯,我想知道逻辑还能做些什么,更不用说《风与火》了……”随着时间的流逝,鲍德瑞克全神贯注地阅读了这本书。

When he was about a quarter of the way through he thought to himself, “Sigh, I suppose it’s time to get back before Kevin wonders where I am.” Looking out a nearby window, he saw it was dark outside. “Wait, that can’t be right. How long have I been here?!” Trading the Book of Magic for the asinine one he had been sent to get, Baldric ran out of the Library, nearly knocking over a pair of half-elves near the entrance, and sprinted back to the office with the requested book in hand.

当他走过大约四分之一的路程时,他心想:“ ,,我想是时候让凯文想知道我在哪里了。” 看着附近的窗户,他看到外面很黑。 “等等,那是不对的。 我在这里待了多长时间?!” 鲍德里克(Baldric)用魔法书替换了他拿来的那本愚蠢的书,就跑出图书馆,差点撞倒了入口附近的一对半精灵,手里拿着所要的书冲向了办公室。

He slipped inside and darted toward his desk but turned a corner and found himself face-to-face with Kevin. This time his mouth was curved in a disappointed frown. His eyes were the same as always.

他滑入室内,冲向书桌,但转过一个弯,发现自己与凯文面对面。 这次他的嘴巴弯曲得令人失望。 他的眼睛和以往一样。

“Baldric, buddy, where’ve you been? I hate to say it, but you really dropped the ball on this one when it should’ve been a no-brainer. I’m almost starting to think you don’t quite fit the culture here. You wouldn’t agree with that assessment, would you?”

“鲍尔德里克,哥们,你去哪儿了? 我讨厌这样说,但是当您本该理智地工作时,您确实将球丢给了它。 我几乎开始认为您不太适合这里的文化。 您不同意这种评估,对吗?

The fires deep in Kevin’s pupils seemed eager for Baldric to agree.

凯文学生深处的大火似乎渴望鲍德瑞克同意。

“No not at all, it’s completely my fault Kevin, it just took me forever to search through the library, and the book wasn’t where…”

“完全没有,这完全是我的错,凯文,这花了我永远的时间来搜索图书馆,而那本书不在那儿……”

“Great, I didn’t think so. Now listen Baldric, there’s actually another request on your desk that I need you to execute on ASAP. So put your pencil to it, and let’s sync up once you’re done banging it out. Then you can give me the whole play-by-play of this little library incident, sound good?”

“太好了,我不这么认为。 现在听Baldric,实际上您的办公桌上还有另一个要求,我需要您尽快执行。 因此,把铅笔放在上面,一旦完成敲打,让我们同步一下。 然后您可以把这个小图书馆事件的全部过程都给我,听起来不错吗?”

Baldric nodded drearily and sat down at his desk. A new request had indeed arrived via letter, sealed with wax imprinted with the likeness of a hand holding a leash and the phrase, “Busyness is Progress”.

鲍德瑞克沉迷地点了点头,坐在他的办公桌前。 确实有一个新的要求通过信件到达,并用蜡封住,上面印有蜡像,上面刻着牵着皮带的手的样子,写着“忙碌是进步”。

“Just my luck, it’s got the Imperial Seal. From someone high up in Management then. Very high up.”

“仅我的运气,就拥有帝国印章。 然后从高层管理人员那里。 很高。”

Sighing with dread, he opened the letter and read:

他恐惧地叹了口气,打开信,读着:

The following calculation is to be performed by under-clerk Baldric Hightower, and him alone. You are required to calculate the product of three numbers. The first number is 4 to the 4th power, from which is subtracted 3 times 19. The second number is 10 to the 3rd power plus 161, all of which is divided by 27. The third number is 2 times 3 times 3 times 23 times 3 times 233 times 43, all of which is subtracted by 5. Multiply these three numbers together, and submit the result directly to your supervisor.

以下计算将由副书记Baldric Hightower和他一个人执行。 您需要计算三个数字的乘积。 第一个数字是4到4的幂,再减去3乘以19。第二个数字是10到3的幂再加上161,所有这些均除以27。第三个数字是2乘以3乘以3乘以23乘。 3乘以233乘以43,将所有这些都减去5。将这三个数字相乘,然后直接将结果提交给主管。

No signature. Baldric scratched his head in thought. “Why would anyone be interested in such an enormously tedious calculation? Or, more importantly, feel compelled to bother me with it?” Cracking his knuckles, he said to himself, “Well whoever they are, I guess they came to the right place. Let’s see what this Magic of mine can really do.”

没有签名。 鲍德瑞克思索着脑袋。 “为什么有人会对如此繁琐的计算感兴趣? 或者,更重要的是,感到被它困扰着吗?” 他ing着指关节,对自己说:“好吧,不管他们是谁,我猜他们来对地方了。 让我们看看我的魔力到底能做什么。”

# notice the lack of ">>>" characters
# this suggests you should try running the code in script mode
# for such code, the result will be displayed here in a separate box

number1 = 4**4 - 3*19 
number2 = (10**3 + 161) / 27
number3 = (2 * 3 * 3 * 23 * 3 * 233 * 43) - 5
final_number = number1 * number2 * number3
print(final_number)
106479825301.0

Once the calculation was completed, Baldric took a moment to stare at the result: 106479825301.0.

计算完成后,Baldric花了一点时间盯着结果:106479825301.0。

“Hmm. There’s something…peculiar about it. I can’t quite put my finger on it though…”

“嗯。 有一些……特别之处。 虽然我不能完全用手指……”

***
***

“Mistress, here’s the response to your request. Completed in remarkably short order I might add.”

“女主人,这是对您要求的回复。 我可能会在很短的时间内完成。”

“Hmm…yes, it seems we will be able to move forward with our plans, thank the Serpent. I trust you two managed to acquire the scrolls of Teleportation and Truth-telling as well?”

“嗯……是的,感谢蛇,看来我们将能够推进我们的计划。 我相信你们两个也设法获得了远传和真相的卷轴?”

“Yes Mistress.”

“是的情妇。”

“Good, then prepare the bait.”

“好,然后准备诱饵。”



Congratulations, you earned 32 experience and 14 gold! You are now a Level 1 Dwarven Novice! (cue victory music)

恭喜,您获得了32点经验和14金! 您现在是1级矮人新手! (提示胜利的音乐

Here are the Python topics you covered (and may want to DuckDuckGo for further inquiry):

这是您涵盖的Python主题(并且可能需要DuckDuckGo进行进一步的查询):

  • integers
  • floats
  • arithmetic
  • modular (clock) arithmetic
  • variables
  • Python data types and the type() function
  • converting between integers and floats with int() and float()
  • coding in interactive mode vs script mode
  • the print() function
  • comments (using the # symbol)
  • 整数
  • 漂浮
  • 算术
  • 模块化(时钟)算法
  • 变数
  • Python数据类型和type ()函数
  • 使用int ()和float ()在整数和浮点数之间转换
  • 交互模式与脚本模式下的编码
  • print ()函数
  • 注释(使用#符号)


翻译自: https://www.pybloggers.com/2017/10/intro-to-python-chapter-1-arithmetic-and-variables/

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值