python-pcl函数



Running through the door, Baldric found himself in an enormous cavern, its ceiling lost in shadow. Great columns of black stone soared from the ground, and pools of lava bubbled throughout, lighting the cavern in a dark red. The heat was suffocating. Baldric saw Bill standing on a stone outcrop nearby, apparently scanning for something. Beyond him, in the center of the cavern, was large mahogany desk. Baldric could just make out the gold nameplate from this distance which read “HR Manager”.

R 1至门unning,佩饰发现自己在一个巨大的洞穴,其上限在阴影中。 巨大的黑色石头柱子从地上飞腾起来,熔岩的池水在整个过程中冒泡,将洞穴照成深红色。 高温令人窒息。 鲍德瑞克看见比尔站在附近的一块石头露头上,显然正在寻找东西。 在他的旁边,是洞穴的中央,是一张大红木桌子。 Baldric可以从这个距离上划出金色铭牌,上面写着“ HR Manager”。

With a disgruntled roar Bill brought his warhammer down on the ground, lava seeping through the resulting fissure. “I come all the way to see the HR Manager, and it’s not even here? Bah, the coward!”

比尔带着不满的吼声将战锤放倒在地,熔岩从裂缝中渗出。 “我一直去看人力资源经理,这不是吗? ah,胆小鬼!”

“Bill,” said Baldric, panting and heaving as he climbed the rocky slope, “The HR Manager isn’t supposed to be here right now.”

“比尔,”鲍德瑞克在攀登岩石坡道时气喘吁吁地说,“人力资源经理现在不应该在这里。”

“What? Not supposed to be here? What makes you say that?”

“什么? 不应该在这里吗? 是什么让你这么说?”

“It’s out devouring the dreams of the workforce right now. If you could see Magic, you would’ve seen its dream web covering the sky tonight. Since you apparently came here to do more than talk with it, I should tell you that I came here to take something from its desk.”

“现在正在吞噬员工的梦想。 如果您可以看到Magic,那么您将可以看到它的梦想之网今晚覆盖了天空。 既然您显然是来这里做的不只是与它交谈,我应该告诉您我来这里是为了从它的办公桌上取走一些东西。”

“So you’re a fellow rebel?” Bill laughed heartily and put his arm around Baldric’s shoulders. “I knew you were a good man. I should tell you, my name isn’t actually Bill. It’s Geofram, Geofram Hammerfell.”

“那么你是叛逆者吗?” 比尔发自内心地笑了起来,将胳膊搭在鲍德瑞克的肩膀上。 “我知道你是个好人。 我应该告诉你,我的名字实际上不是比尔。 是Geofram,Geofram Hammerfell。”

A glass-shattering shriek pierced the cavern, and a massive black body fell from the shadows above, its landing crushing boulders and splashing lava. It was an obsidian-scaled creature out of a nightmare with four heads, eight legs, and two wings like the sails of some warship of the damned. The creature extended its wings and let out another deafening screech (cue battle music).

玻璃破碎的尖叫声刺穿了洞穴,一个巨大的黑色尸体从上方的阴影中掉落,其着陆压碎了巨石和飞溅的熔岩。 这是一个噩梦般的黑曜石级生物,它有四个头,八个腿和两个翅膀,就像该死的某些军舰的帆一样。 该生物张开翅膀,发出另一种震耳欲聋的尖叫声(提示战斗音乐 )。

Geofram threw his head back and roared with laughter. “Quite a pair of lungs you’ve got there, oh fearsome HR Manager. Let’s see what they look like!” With that, he leapt off the stone outcrop and charged the beast, running between lava pools and letting out a fierce battlecry of his own.

Geofram朝后仰起头,大笑起来。 “您的肺部有很多,令人恐惧的人力资源经理。 让我们看看它们的外观!” 就这样,他跳下了石头露头,冲上了野兽,在熔岩池之间奔跑,发出了自己激烈的战斗声。

For a split second, Baldric thought the creature was actually turning to run! Then he saw a thick, scaly tail whipping around from the side, crashing through columns of rock, and cringed at the sickening crunch of it impacting with Geofram. Baldric watched in horror as the warrior sailed through the air and slammed into the side of the cavern. He didn’t get up.

一瞬间,鲍德瑞克以为这个生物实际上正在奔跑! 然后他看到一条粗而鳞状的尾巴从侧面打来打去,撞破了几列岩石,并为它的令人作呕的紧缩而畏缩,这影响了Geofram。 当战士在空中航行并猛撞到洞穴的一侧时,鲍德瑞克惊恐地看着。 他没有起床。

Completing its spin to face Baldric’s direction once again, the four faces of the HR Manager appeared to be smiling. One of those heads opened its mouth and, to Baldric’s surprise, started weaving threads of Magic. It was a simple but powerful weave of pure fire, likely some sort of fire-based projectile. Frantically, Baldric thought back to the Book of Magic.

人力资源经理的四张脸再次完成旋转以面对Baldric的方向,似乎在微笑。 其中一个头张开嘴,令鲍德瑞克惊讶的是,他们开始编织魔术的线。 这是一种简单而强大的纯火编织,可能是某种基于火的弹丸。 疯狂地,鲍德瑞克回想起《魔法书》。

“Taken in its entirety, the multiverse is in perfect magical balance. Water balances with Fire…”

综上所述,多元宇宙处于完美的魔幻平衡中。 水与火保持平衡……”

“Of course, Water cancels out Fire! So I just need to…” In the middle of thought, the weave completed and a bolt of molten flame shot through the air at Baldric’s head. In a panic he slipped and tumbled down the rocky slope, feeling the heat from the bolt of fire that passed through where his head had been a moment ago.

“当然,水可以消除火! 因此,我只需要……”在思考的中间,编织完成了,一束熔化的火焰从空气中喷向Baldric的头。 惊慌失措的他滑了下来,跌落在岩石山坡上,感到一瞬间的火光从头顶传过。

Getting up on his knees, he crouched behind some rocks. “There’s no time to think, I just have to react. But I don’t know this stuff by heart yet! Wait, maybe I can use a conditional statement to tell me what element to counter with.”

他跪下来,蹲在一些岩石后面。 “没有时间去思考,我只需要做出React。 但是我还不知道这些东西! 等等,也许我可以使用条件语句告诉我要应对的要素。”

attack = "Fire"
if attack == "Fire":
print("Counter with Water!")
elif attack == "Water":
print("Counter with Fire!")
else:
print("Dodge!")
Counter with Water!

“That seems to work. Now I just need to add in the rest of the elements. Let’s see, I think the Book said Wind balances with Earth, and…”

“这似乎行得通。 现在,我只需要添加其余元素。 让我们看看,我认为这本书说风与地球保持平衡,……”

Baldric’s cover exploded into fragments, sending him flying several feet. Gathering himself, he turned to see more Magic being prepared by one of the heads. It looked like Earth this time.

鲍德瑞克的外衣破裂成碎片,使他飞了几英尺。 他聚在一起,转而看到更多的魔术师正在准备其中的一个。 这次看起来像地球。

attack = "Earth"
if attack == "Fire":
print("Counter with Water!")
elif attack == "Water":
print("Counter with Fire!")
elif attack == "Wind":
print("Counter with Earth!")
elif attack == "Earth":
print("Counter with Wind!")
else:
print("Dodge!")
Counter with Wind!

By the time Baldric finished with his conditional statement though, a great earthen spike was already descending on him from above. Without time to respond magically, he rolled to the side just in time to avoid impalement. Shrouded in a cloud of debris, he scrambled over to another stone outcrop and took a moment to strategize.

到鲍德瑞克完成他的条件声明时,一个巨大的土钉已经从上方降落在他身上。 由于没有时间做出神奇的React,他及时赶到身边以避免刺穿。 他笼罩在一片碎屑中,争先恐后地摸索到另一块石头露头,花了一些时间进行战略规划。

“I don’t have time to think through what I need to counter with, and I don’t have time to weave a full conditional statement for every single spell either. If only I could weave this conditional Magic just once, and reuse it whenever it was needed without weaving it all over again…Oh yeah that’s right, I need to use functions! I can bundle up a bunch of Logic inside a function and reuse it in an instant.”

“我没有时间去思考我需要应对的问题,而且我也没有时间为每个咒语编织完整的条件陈述。 如果我只能编织一次此条件式Magic,然后在需要时重用它而又不重新编织它……哦,是的,我需要使用函数! 我可以将一堆Logic捆绑在一起,然后立即重用。”

# create a function named counterattack like so
# note that the name of the function and its input can be anything you want
# also note how everything inside a function must be indented
def counterattack(attack):
if attack == "Fire":
print("Counter with Water!")
elif attack == "Water":
print("Counter with Fire!")
elif attack == "Wind":
print("Counter with Earth!")
elif attack == "Earth":
print("Counter with Wind!")
else:
print("Dodge!")

“So there’s my function. Now I just have to feed in the element of attack, and then the Logic will run without me having to weave the whole conditional statement over again. Not to mention I can reuse the function endlessly.”

“这就是我的职责。 现在,我只需要提供攻击要素,然后逻辑将运行而无需我重新编织整个条件语句。 更不用说我可以无休止地重用该功能。”

# let's test it out
>>> counterattack("Water")
'Counter with Fire!'
>>> counterattack("Earth")
'Counter with Wind!'

He could hear the creature breathing, but it apparently didn’t know where he was. A boulder nearby exploded, and Baldric peered out from behind his rocks to see the manager turning towards his position next. It was forming another Fire attack.

他可以听到生物的呼吸,但显然不知道他在哪里。 附近的一块巨石爆炸了,鲍德瑞克从岩石后面瞥了一眼,看到经理正转向他的位置。 它正在形成另一场火灾袭击。

>>> counterattack("Fire")
'Counter with Water!'

Using his function, Baldric instantly knew what to counter with. Just as the fire spell was released, Baldric finished his own simple weave of Water, and a jet of water met firebolt midair and exploded in a harmless burst of vapor. The creature seemed stunned for a moment, then responded with a barrage of attacks: Earth, then Water, then Wind. But Baldric was prepared.

使用他的功能,Baldric立即知道该如何应对。 正当放出火咒时,鲍德瑞克完成了自己的简单编织工法,一股水柱碰到了半空中的火箭,并在无害的蒸气中爆炸。 该生物似乎被惊呆了片刻,然后发出一连串的攻击:地球,然后是水,然后是风。 但是鲍德瑞克已经准备好了。

>>> counterattack('Earth')
'Counter with Wind!'
>>> counterattack('Water')
'Counter with Fire!'
>>> counterattack('Wind')
'Counter with Earth!'

Baldric wove Magic faster than he ever had before, countering Earth with Wind, Water with Fire, and Wind with Earth. Seeing all of its attacks nullified, the beast shrieked in rage and began to craft a new attack.

鲍德瑞克(Baldric)用前所未有的速度编织魔法,用风,水,火和风与地球对抗地球。 看到它的所有攻击都无效,野兽愤怒地尖叫着,开始制作新的攻击。

“Wait, that’s different from the other attacks. What is that!? It looks like Water, Earth, and Wind all at once. Uh oh.”

“等等,这与其他攻击不同。 那是什么!? 看起来像是水,地球和风。 哦哦。”

Baldric’s hair stood on end and the air crackled with energy. A figure landed on the ground in front of him just as a blinding light and deafening boom nearly knocked Baldric over. Once his vision recovered, he saw Geofram standing in front of him, electricity arcing throughout his plate mail, his great hammer raised straight overhead.

鲍德瑞克的头发直立,空气充满了能量。 一个人影降落在他面前的地面上,就像一道令人目眩的灯光和震耳欲聋的轰炸声几乎将Baldric撞倒了。 视力恢复后,他看到Geofram站在他的面前,整个印版邮件中都闪着电弧,他的大铁锤直接举过头顶。

Geofram threw back his head and laughed. “Bahahaha, well that sure woke me up! And now it’s time to put you to sleep, foul beast. Baldric, you and me, let’s finish this thing.”

Geofram退回头笑了。 “巴哈哈哈,那肯定使我醒了! 现在是时候该睡觉了,犯规的野兽。 Baldric,您和我,让我们完成这件事。”

“Geofram, I need a moment to work something out.”

“ Geofram,我需要一点时间来解决问题。”

“Alright, I’ve got you covered, friend.”

“好吧,朋友,我已经覆盖了你。”

The HR Manager let loose a barrage of elemental attacks. Wielding his hammer, Geofram stood in front of Baldric and deflected firebolts, earthen spikes, and spears of ice, one after another.

人力资源经理松开了一系列基本攻击手段。 Geofram挥舞着锤子,站在Baldric的前面,偏转了火苗,土钉和冰矛。

Baldric took the chance to weave the ultimate counterattack function, based on everything he remembered from the Book of Magic.

根据他从《魔法书》中记得的所有内容,鲍德瑞克借此机会编织了终极的反击功能。

# to account for combos of elements, the function needs to be structured differently
# its inputs will be 5 booleans (True or False) based on whether a given element is involved or not
def counterattack(fire, water, earth, wind, logic):
# light
if (fire and water and earth and wind and logic):
print("Counter with Darkness (all elements but Logic)!")
# darkness
elif (fire and water and earth and wind):
print("Counter with Light (all elements)!")
# lightning
elif (water and earth and wind):
print("Counter with Fire, Earth and Wind!")
# ice
elif (water and wind):
print("Counter with Lava (Fire and Earth)!")
# lava
elif (fire and earth):
print("Counter with Ice (Water and Wind)!")
elif fire:
print("Counter with Water!")
elif water:
print("Counter with Fire!")
elif wind:
print("Counter with Earth!")
elif earth:
print("Counter with Wind!")
else:
print("I don't know, take cover!")

The four heads were all casting spells now, a constant stream of firebolts and ice shards, molten lava and chunks of rock. Hammerfell, with his gleaming warhammer, danced gracefully from one stance to another as his weapon whirled through the air with inhuman speed and repelled attack after attack. Above Hammerfell, Baldric could see the HR Manager preparing that same mix of Water, Earth, and Wind as before.

四个脑袋现在都在施放魔法,持续不断的喷火和碎冰,熔岩熔岩和大块岩石。 Hammerfell带着闪闪发光的战锤,以一种人性的姿态从一种姿势优雅地跳到另一种姿势,他的武器以不人道的速度在空中旋转,并击退了攻击。 在Hammerfell上方,Baldric可以看到人力资源经理像以前一样准备水,土和风。

>>> counterattack(False, True, True, True, False)
'Counter Lightning with Fire, Earth and Wind!'

Not sure what to expect, Baldric wove Fire, Earth, and Wind together in a way that intuitively seemed protective in nature. A nearly transparent dome formed over him and Hammerfell just as the lightning struck. The blinding bolt crashed into the barrier with a roar and was gone, not leaving so much as a mark on the dome. But the creature was already forming more spells: lava, then fire, then ice.

不知道会发生什么,Baldric用一种直观上看起来很自然的方式一起编织了火,土和风。 雷电袭来时,一个几乎透明的圆顶在他和Hammerfell上方形成。 致盲的螺栓轰鸣着冲入障碍物,消失了,没有在圆顶上留下太多的痕迹。 但是生物已经形成了更多的咒语:熔岩,然后是火,然后是冰。

>>> counterattack(True, False, True, False, False)
'Counter Lava with Ice (Water and Wind)!'
# when there are lots of arguments, you can use their names to clarify what's happening
# in this case, it's now obvious from the function call that only Fire is involved
>>> counterattack(fire=True, water=False, earth=False, wind=False, logic=False)
'Counter with Water!'
# if you use argument names, you can change the order of arguments and it still works like it should
>>> counterattack(water=True, earth=False, wind=True, logic=False, fire=False)
'Counter Ice with Lava (Fire and Earth)!'

Using his counterattack function, Baldric took over on defense and negated the entire Magical flurry. A wall of ice blocked a wave of lava, a jet of water cancelled out a bolt of fire, and pillars of molten rock deflected ice spears.

使用他的反击功能,鲍德瑞克接管了防守,并取消了整个魔术比赛。 一堵冰墙挡住了熔岩的浪潮,一股水流抵消了一束火,熔岩的柱子使冰矛偏转了。

“Looks like you’ve got a handle on the beast’s magic tricks Master Baldric, so I’d say it’s time for a little offense.” And with that, Hammerfell charged at the monster once again. A furious stream of lethal Magic rained down on Hammerfell, but Baldric made sure it never touched him. As Hammerfell closed the distance, Baldric saw the attacks stop as all four heads seemed to be working together on one massive spell, weaving together Fire, Water, Earth, and Wind all at once. A dark, throbbing mass that seemed to absorb the light around it formed in the air.

“看起来您已经掌握了野兽大师鲍德里克大师的魔术技巧,所以我想是时候该冒犯了。” 然后,哈默菲尔再次向怪物冲锋。 致命的魔术狂暴地降落在Hammerfell上,但是Baldric确保它永远不会触及他。 当Hammerfell靠近距离时,Baldric看到攻击停止了,因为所有四个头似乎都在一个巨大的咒语下共同努力,将火,水,土和风全部编织在一起。 黑暗的,mass动的团块似乎吸收了空气中的光。

>>> counterattack(True, True, True, True, False)
'Counter Darkness with Light!'

Frantically, Baldric channeled raw Light Magic at the orb, weaving all five elements together in as great a quantity as he could muster. A beam of Light from Baldric’s hand impacted the orb, which seemed to weaken but not destroy it. The HR Manager roared and the still sizeable orb of darkness flew at Hammerfell.

疯狂地,鲍德瑞克将原始的光魔导引到球体上,将所有五个元素编织在一起,使数量尽可能多。 鲍德瑞克手中的一束光束撞击了这个球体,它似乎减弱了但没有破坏它。 人力资源经理怒吼着,还有仍然很大的黑暗之球飞向Hammerfell。

“Geofram, look out!” As the pulsating orb hurtled toward Hammerfell, his hammer suddenly began to glow with a radiant light. It was far brighter than even Baldric’s beam had been. Gleaming hammer connected with Darkness, and in a brilliant flash the orb was gone. His path now clear, Hammerfell leapt into the air with a roar as his hammer grew brighter still. Baldric shielded his eyes from the blinding light, and otherworldly screams erupted in the cavern like a chorus of demons being simultaneously immolated.

“ Geofram,当心!” 当脉动的球撞击哈默费尔时,他的锤子突然开始发出辐射光。 它甚至比鲍德瑞克的光束还要明亮。 闪闪发光的锤子与黑暗联系在一起,闪闪发光的球消失了。 现在他的路已经清晰了,随着锤子变得越来越亮,哈默菲尔咆哮着跳了起来。 鲍德瑞克挡住了他的眼睛,使之免受刺眼的光芒,超凡脱俗的尖叫声在山洞中爆发,就像一团恶魔同时被献出。

After picking himself up and blinking through the spots in his eyes, Baldric saw the remains of the HR Manager splattered across the cavern. Hammerfell strolled back over towards Baldric, casually wiping oily black blood off his hammer with his cloak as he walked.

抬起头来,眨了眨眼之后,鲍德瑞克看到了人事经理的遗物溅落在洞穴中。 Hammerfell朝Baldric走去,在走动时随便用斗篷擦掉了锤子上的油性黑血。

“That was incredible Geofram! We’d better get out of here though. That demonic cacophony probably woke half the city.”

“那真是令人难以置信的Geofram! 我们最好还是离开这里。 那恶魔般的刺耳声可能唤醒了整个城市的一半。”

“Actually, this is where we must part ways, Baldric my friend. There’s much of dire importance still to do, and there’s no time for me to be wandering through any more labyrinths. Not to mention that you’ll be fine without me, you clearly know how to handle yourself. One question before I go though. This probably seems like an odd thing to ask, but how do you convert a binary…I think that’s what it’s called, you know, a number with all 1’s and 0’s…into a regular decimal number?”

“实际上,这是我们必须分开的地方,我的朋友鲍德瑞克。 仍然有许多非常重要的事情要做,没有时间让我徘徊在更多的迷宫中。 更不用说没有我,你会没事的,你清楚地知道如何应付自己。 不过我要问一个问题。 要问这似乎很奇怪,但是如何将二进制数转换为……我认为这就是所谓的,将全为1和0的数字…转换为常规十进制数字吗?”

After a moment of thought, Baldric remembered that the int() function he had used in the past had a second optional argument that could be used to convert a binary string into a decimal number. For instance…

片刻之后,Baldric记得他过去使用过的int ()函数具有第二个可选参数,该参数可用于将二进制字符串转换为十进制数字。 例如…

>>> int('101', 2)
5
>>> int('11000', 2)
24

“Well Bill, if you can use Logic it’s pretty simple, but it might take a little explaining if you want to do it by hand.”

“好吧,比尔,如果您可以使用Logic,这很简单,但是如果您想手工完成,可能需要一些解释。”

“Argh, nevermind Master Baldric, I’m no good with channeling Magic except for wielding Light through my hammer, and I really must be off. Oh, I found this in the ruins of the desk, figure it must be what you came here for,” said Hammerfell, handing a small, black metal lockbox to Baldric. “I pray that our paths cross once again.” And with that, Hammerfell darted up the side of the cavern wall, leaping from ledge to ledge until he disappeared into the shadows above and the sound of his passage was lost to the darkness.

“啊,没关系,鲍德瑞克大师,我除了引导我的锤子挥舞光魔之外,对引导魔术师没有任何帮助,我真的必须离开。 哦,我在书桌的废墟中发现了这个,想必它一定是您来这里的目的。”哈默菲尔说,将一个小的黑色金属密码箱交给了鲍德瑞克。 “我祈祷我们的道路再次相交。” 于是,哈默菲尔飞快地爬上了洞穴壁的一面,从壁架一跃而下,直到他消失在上面的阴影中,而穿越的声音消失在黑暗中。

Baldric noticed now that there were in fact two doors in the cavern: the one he had entered through, and a second similar one which was closed. As he reentered the first door, he could hear what sounded like a distant rumble and clinking. It sure sounded a lot like armored guards in a rush. He hurried back out and over to the second door. It opened silently, and he closed it behind him.

鲍德瑞克现在注意到,实际上洞穴里有两扇门:他进入的那扇门,和第二扇类似的关门。 当他重新进入第一扇门时,他可以听到听起来像是遥远的隆隆声和叮当响。 听起来确实很像匆忙中的装甲警卫。 他匆匆走回去,走到第二扇门。 它无声地打开,他把它关在身后。

He was in an earthen tunnel that sloped upward. Baldric jogged up the slope as fast as he could, which wasn’t saying much. Almost out of breath and the shuffle of armored feet echoing throughout the tunnel, he found himself in a chamber much like those he had passed through to get to the HR Manager’s office. Across from him though, instead of multiple doors, was a single heavy stone door.

他在一条向上倾斜的土制隧道中。 鲍德里克(Baldric)尽可能快地在斜坡上慢跑,这没多大意思。 他几乎喘不过气来,整个隧道里回荡着装甲的脚步,他发现自己像进入人力资源经理办公室时所经过的房间一样。 但是在他对面,是一扇沉重的石门,而不是多扇门。

On each side of the doorway was a number. And on the ceiling there was what appeared to be instructions for some sort of Magical procedure: “Add 11, multiply by 13, raise to the power of 17, and find the remainder of division with 19. Do this for each of x, y, and z, and answer with the sum.”

门口的每一侧都有一个数字。 天花板上似乎有某种魔术程序的说明:“加11,乘以13,升为17的幂,找到除法的余数为19。对x,y中的每个进行此操作,z并以总和回答。”

The numbers around the door were 3, 5, and 7.

门周围的数字分别是3、5和7。

“Okay, okay, I need to think quickly now. It looks as if I need to perform the same procedure three different times. I can probably use a function to speed things up in that case.”

“好的,好的,我现在需要快速考虑。 好像我需要在三个不同的时间执行相同的过程。 在这种情况下,我可能可以使用一个函数来加快处理速度。”

def procedure(number):
number = number + 11
number = number * 13
number = number**17
number = number % 19
>>> procedure(3)

“…nothing happened. Ugh, come on…oh that’s right, I need a print() statement to see the result.

“…什么都没有发生。 gh,拜托...哦,是的,我需要一个print()语句才能看到结果。

def procedure(number):
number = number + 11
number = number * 13
number = number**17
number = number % 19
print(number)
>>> procedure(3)
7

“Great, yeah, but I also want to store that result so I can later add it to the other results.”

“很好,是的,但是我也想存储该结果,以便以后可以将其添加到其他结果中。”

>>> result1 = procedure(3)
7
>>> print(result1)
None

“Something isn’t right here. When I call the function and assign it to result1, it’s printing the result. I guess that makes sense, since that’s what the function is supposed to do when it’s called. But it’s not actually assigning that number to the variable result1. How can I…oh I remember now, that’s what return statements are for!”

“这里不对劲。 当我调用该函数并将其分配给result1时 ,它将打印结果。 我猜这是有道理的,因为这就是调用函数时应该执行的操作。 但这实际上并没有将该数字分配给变量result1 。 我怎么能……哦,我现在记得,这就是return语句的目的!”

# the print function just displays objects
# return statements make those objects actually usable
def procedure(number):
number = number + 11
number = number * 13
number = number**17
number = number % 19
return number
>>> result1 = procedure(3)
# notice that nothing was printed this time
# let's see if result1 actually contains something now
>>> print(result1)
7
# success

“There we go. Now instead of just displaying the result, the procedure() function actually outputs, or returns, the result, meaning it can be used in calculations or stored in variables and things like that (i.e. >>> procedure(3) + procedure(5) works and will sum the results of those two function calls). Now I just need to do this with the other two numbers, then sum them all together.”

“我们去了。 现在,不仅仅是显示结果, procedure ()函数实际上输出或返回结果,这意味着它可以用于计算或存储在变量中,例如(>> >> procedure(3)+ procedure(5 )工作,并将这两个函数调用的结果相加)。 现在,我只需要对其他两个数字进行运算,然后将它们加在一起即可。”

>>> result2 = procedure(5)
>>> print(result2) # checking to make sure it's working
18
>>> result3 = procedure(7)
>>> print(result3)
16
>>> final_result = result1 + result2 + result3
>>> print(final_result)
41
# also try the quicker >>> print(procedure(3) + procedure(5) + procedure(7))

“Forty one!” Baldric called out. The stone door immediately swung open and Baldric hurried inside. It was dark except for the light from the torches in the chamber he had just left. There was a snap, and something nicked his ear. He instinctively dropped to the ground just as two more arrows shot over him. He turned as he fell and saw the chamber beyond the door filling with Imperial guards, several with bows drawn. He also saw that this end of the magical stone door had a different set of symbols by each of its sides, and he could just make out some text on the ceiling:

“四十一!” 鲍德瑞克喊了出来。 石头门立即打开,鲍德瑞克急忙进去。 除了他刚离开的房间里的火把发出的光以外,那是一片黑暗。 突然,他的耳朵有些刺痛。 他本能地跌倒在地,就像另外两个箭在他身上射出一样。 他跌倒时转过身,看到门外的房间里充满了帝国卫队,其中一些人拉着弓。 他还看到,魔法石门的这一端在其每一侧都有不同的符号集,他可以在天花板上做出一些文字:

  • Left of doorway: [41, 29, 17, 7]
  • Above doorway: [37, 23, 13, 5]
  • Right of doorway: [31, 19, 11, 3]
  • Ceiling: To the first add the second. Take of the product of the sum and the third. Raise the product to the fourth. Do this for each, and sum the results.
  • 门口左侧:[41、29、17、7]
  • 门口上方:[37、23、13、5]
  • 门口右边:[31、19、11、3]
  • 天花板:在第一个添加第二个。 取总和与第三乘积的乘积。 将产品提高到第四位。 对每个对象执行此操作,然后对结果求和。

As Baldric hit the ground he thought to himself, “My only chance is if solving this puzzle closes the door. I need to write a function that can take a list as input.”

当鲍德瑞克(Baldric)摔倒在地时,他心想:“我唯一的机会是,解决这个难题是否能关门。 我需要编写一个可以将列表作为输入的函数。”

Once you have computed the answer, click here to continue计算出答案后,请点击此处继续
def procedure(number_list):
answer = number_list[0]
answer = answer + number_list[1]
answer = answer * number_list[2]
answer = answer ** number_list[3]
return answer
l1 = [41, 29, 17, 7]
l2 = [37, 23, 13, 5]
l3 = [31, 19, 11, 3]
final_answer = procedure(l1) + procedure(l2) + procedure(l3)
print(final_answer)

3379315706501993175000

Thinking and weaving faster than he ever had before, Baldric finished his Logic and printed out the result, causing the heavy stone door to swiftly swing closed. He rolled out of the way of a few more arrows, and with a satisfying thud the door was shut and all was silent. Still out of breath, he touched his ear and saw blood on his fingers. Panting, he thought to himself, “Whew, that was a close one. Hopefully no Logic casters are back there.” He stood there for a minute, catching his breath and watching the door. It didn’t budge.

思考和编织比以往任何时候都要快,Baldric完成了Logic并打印出结果,导致沉重的石头门Swift关闭。 他从另外几支箭的方向上滚了出去,发出令人满意的轰鸣声,门关了,所有人都安静了。 仍然气喘吁吁,他摸了摸耳朵,看到手指上有血迹。 他自言自语地喘着粗气,“哇,那是亲密的。 希望没有逻辑脚轮回到那里。” 他站在那里一分钟,屏住呼吸,看着门。 它没有让步。

“I…I think I did it. Haha, I did it! Yes sir, this old dwarf’s still got the Magic, boom! Take that Empire! You can’t fire me, because I QUIT!!! HA!!!!!”

“我……我想我做到了。 哈哈,我做到了! 是的,先生,这个小矮人仍然拥有魔法,繁荣! 以那个帝国! 你不能解雇我,因为我退出了!!! 哈!!!!!”

“I’ll be the judge of that.”

“我将担任法官。”

Baldric nearly fell over in shock at the unexpected voice. He turned around to see Cassandra silently walking towards him.

鲍德瑞克差点被意外的声音吓了一跳。 他转过身去,看到卡桑德拉默默地走向他。

“Cassandra! Hoo boy, you sure frightened me. Here, I got your lockbox. Glad to see you somehow escaped, by the way. You won’t believe what just happened. Me and…” Cassandra’s spin-kick took Baldric off his feet and sent him crashing into the stone floor. As he struggled to process what had just happened, she placed her foot over his throat. “I thought you might end up here. Just a little ways from HR’s facility actually. How thoughtful, you won’t need to be carried far at all.”

“卡桑德拉! 哎呀,你肯定吓坏了我。 在这里,我得到了您的密码箱。 顺便说一句,很高兴看到您逃脱了。 您不会相信刚刚发生的事情。 我和……”卡桑德拉的自发踢使鲍德瑞克脱下脚步,使他坠入石地板。 当他努力处理刚刚发生的事情时,她把脚放在他的喉咙上。 “我以为你可能会到这里来。 实际上,离HR的设施只有几步之遥。 多么周到,您根本不需要被带走。”

He noticed several figures emerging from the shadows around him, including two half-elves that looked vaguely familiar. Baldric began weaving Magic. Maybe he could use that same barrier that blocked the lightning to give him some time to…all at once he felt the Magic drain out of him, as if a well had suddenly run dry. The individuals around him were weaving complex Magic that seemed to be blocking his own. All of them bore the Imperial Seal on their robes. Management.

他注意到周围的阴影中出现了几个人物,包括两个看上去隐约熟悉的半精灵。 鲍德瑞克开始编织魔术。 也许他可以使用阻挡闪电的屏障来给他一点时间……他立刻感到魔力正在流失,好像一口井突然干dry了。 他周围的人编织着复杂的魔术,似乎在阻止他自己。 他们所有人都穿着长袍戴上圣印章。 管理。

“Cassandra, I don’t know what’s going on, but…”

“卡桑德拉,我不知道发生了什么,但是……”

“Save your breath, dwarf. You’ll need it for screaming during your performance review.”

矮人,喘口气。 在效果评估期间,您需要它来尖叫。”

Something struck Baldric’s head. Darkness.

鲍德瑞克的脑袋有些动静。 黑暗。



Congratulations, you earned 2,568 experience and 1,542 gold! You are now a Level 6 Dwarven Evoker! (cue victory music)

恭喜,您获得了2568点经验和1,542金币! 您现在是6级矮人召唤者! (提示胜利的音乐 )

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

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

  • functions
  • function inputs, referred to as arguments (if referring to function call) or parameters (if referring to the function itself)
  • named and unnamed function arguments
  • function outputs via the return statement
  • None (which functions return by default)
  • the difference between printing and returning something in a function
  • converting from binary to decimal
  • 功能
  • 函数输入,称为参数(如果引用函数调用)或参数(如果引用函数本身)
  • 命名和未命名函数参数
  • 通过return语句输出函数
  • 无(默认情况下返回的函数)
  • 函数中打印和返回内容之间的区别
  • 从二进制转换为十进制


Join the Rebellion 加入叛乱

翻译自: https://www.pybloggers.com/2017/11/intro-to-python-chapter-4-functions/

python-pcl函数

python-pcl函数_Python简介,第4章-函数相关推荐

  1. python函数装饰函数_Python精进-装饰器与函数对象

    本文为<爬着学Python>系列第四篇文章. 从本篇开始,本专栏在顺序更新的基础上,会有不规则的更新. 在Python的学习与运用中,我们迟早会遇到装饰器,这个概念对于初识装饰器的新手来说 ...

  2. python cookbook 自营_Python Cookbook总结 7-8 章

    第八章和第九章的知识点超级多...建议这两章直接看书复习就行了... 第七章 函数 7.1 将元数据信息附加到函数参数上 函数的参数注解可以提示程序员该函数应该如何使用,这是很有帮助的.比如,考虑下面 ...

  3. python一共有多少个内置函数_Python 35个内置函数,你都ok吗?

    Python一共有60多个内置函数,今天先梳理其中35 个 1 abs() 绝对值或复数的模 In [1]: abs(-6) Out[1]: 6 . 2 all() 接受一个迭代器,如果迭代器的所有元 ...

  4. python中locals函数_Python神奇的内置函数locals的实例讲解

    摘要 本文我们介绍神奇的locals函数,包括动态创建变量和动态访问变量,以及一个应用场景. 相同属性不相邻问题 需求:有两个list,分别为list1和list2.list1中有n个对象,每个对象有 ...

  5. python nums函数_Python中的内置函数

    Python中有很多内置函数,不需要我们调用模块可以直接使用,而且都是常用函数的封装,下面我们来看看Python中的内置函数都有那些. 1.abs() abs()是绝对值函数,把一个负数转化为正数,数 ...

  6. python中求差的函数_Python编程基础11:函数和模块

    一.函数和模块概述 (一)函数概述 函数可以看成是语句的集合,通过函数调用来执行其包含的语句.函数可以返回一个计算结果,根据每次函数调用的参数,可以返回不同的计算结果.Python利用函数提高代码的重 ...

  7. python 匿名回调函数_Python面试题之回调函数

    编程分为两类:系统编程(system programming)和应用编程(application programming).所谓系统编程,简单来说,就是编写库:而应用编程就是利用写好的各种库来编写具某 ...

  8. python中len和range函数_Python中len()和range()函数

    函数:len() 1:作用:返回字符串.列表.字典.元组等长度 2:语法:len(str) 3:参数: str:要计算的字符串.列表.字典.元组等 4:返回值:字符串.列表.字典.元组等元素的长度 5 ...

  9. python画梅花_Python学习笔记三:函数

    1 #!/usr/bin/env python 2 #coding:utf-8 3 4 'a test module' 5 6 __author__ = 'Sunflower' 7 8 9 ## 一. ...

  10. python 类函数调用外部函数_python类中调用外部函数,python 函数中 定义类

    Q1:python函数里的数组如何在函数外调用出来 使用返回值的方法有两种: 可以直接把调用的函数作为变量使用 可以用调用函数给一个变量赋值 第一种情况见如下例子: l = [1,2,3,4,5] d ...

最新文章

  1. rhel6Inode详解
  2. WPF解析TTF 字体
  3. STC10F10XE定时器中断输出10KHz的方波程序
  4. 语言学生学籍管理系统流程图_基于C语言的学生管理系统(含文件)(一)
  5. 16.实现多个具有相同方法的接口和父类与实现接口有相同方法
  6. 做人的态度,本人的工作和生活的感悟。
  7. 【C++ grammar】Enhancement for Type System (C++11 对类型系统的增强)
  8. 【LeetCode笔记】剑指Offer 41. 数据流中的中位数(Java、堆、优先队列、知识点)
  9. 【lucene】lucene 高级搜索
  10. [Python] Numpy Learning
  11. “死去活来”罗永浩:我就做千元机,你能把我怎么着!
  12. java怎么连高斯数据库_Gauss DB 数据库使用(二) Data Studio
  13. 测试金士顿固态硬盘软件,金士顿固态硬盘优化工具(Kingston Toolbox)
  14. opencv大津算法二值化
  15. navicat建mysql数据库密码_Navicat修改MySQL数据库密码的多种方法
  16. 建设工程项目全寿命周期管理是指_工程项目全寿命周期管理.ppt
  17. 戴尔笔记本电脑重装Win10 Pro 后,开机慢的解决方法,DELL Vostro 3420
  18. php中怎样把图片改大,PHP怎么批量修改图片大小?
  19. 十一小长假来临,智能安防监控如何成为民众安全的“守护者”?
  20. python编写自动化脚本工具_blog/技巧与工具04-python控制鼠标自动化点击脚本.md at master · tigeroses/blog · GitHub...

热门文章

  1. Python|使用PIL增强视频画质
  2. 自动驾驶高精地图调研
  3. 本科科研经历(技术干货篇-论文发表流程)
  4. 简历项目描述过程详解
  5. 把电脑端的图片链接转换为API接口可以调用的链接
  6. r5 5600u和锐龙r5 4500u的区别
  7. Unity2D游戏开发—— 解决主角连跳小BUG(在空中无限跳)
  8. 一图掌握项目管理的20条锦囊妙计
  9. java程序设计清华大学出版社_清华大学出版社-图书详情-《Java程序设计基础》...
  10. exhentai服务器不稳定,Exhentai的正确打开方式(以Chrome浏览器为例)