您如何获得菲律宾认证

A Python quiz to check if you’re a true Filipino.

Python测验,检查您是否是真正的菲律宾人。

I’ll be honest with you. I’m 100% Filipino (and I’m so proud of that) but I failed this quiz. But it’s not what you think.

我会对你诚实。 我是100%的菲律宾人(对此我感到非常自豪),但我没有通过本测验。 但这不是您的想法。

I failed to code the quiz properly before anyone could even answer it. Simply because my code did not work as it was supposed to be.

在没有人回答之前,我无法正确编码测验。 仅仅是因为我的代码无法正常运行。

It was frustrating. Then I got more frustrated seeing the codes of my co-scholars who presented, and I was just amazed how elegant their code is, and how they get to code like that after just 8-hours of Python lecture class. Well, I know some of them already have the advantage because they’ve already been using the language for work, and some took a prior course before class.

真令人沮丧。 然后,我看到我的共同学者的代码感到沮丧,我只是惊讶于他们的代码多么优雅,以及仅仅经过8个小时的Python讲座,他们如何才能像这样编写代码。 好吧,我知道其中一些人已经具有优势,因为他们已经在使用这种语言进行工作了,还有一些人在上课之前就读过课程。

And to keep things short, today’s class just slap me in the face and said “Keep up Jela!”. Well, challenge accepted!

为了简短起见,今天的课只是在脸上打我一巴掌,说:“保持耶拉!”。 好吧,挑战接受了!

I first wrote my code in Colab and define functions without fully understanding how functions are supposed to work. So time is almost up but I’m still rerunning my code, trying to figure out why I got it wrong. And during the last minute, I rewrite my code and take out all the functions. Finally, it worked! See the link below to check it out.

我首先用Colab编写了代码,然后在未完全理解函数应如何工作的情况下定义函数。 所以时间差不多了,但我仍在重新运行我的代码,试图弄清楚为什么我弄错了。 在最后一分钟,我重写了代码并删除了所有功能。 终于成功了! 请参阅下面的链接进行检查。

Image for post
Certified Filipino Quiz #1
菲律宾认证测验#1

As you can see, it is an abuse of the text code feature in Colab. I just realized that after seeing the works of my co-scholars (Thank you FTW-DS4 sisters for making me realize that!)

如您所见,这是对Colab中文本代码功能的滥用。 我刚刚意识到,在看到我的共同学者的作品之后(谢谢FTW-DS4姐妹们让我意识到了这一点!)

But I assure you it’s working. You just have to run the code yourself.

但我向您保证,它是有效的。 您只需要自己运行代码。

After class, I continue coding and did not stop until I get the proper one. Hence, this is my Certified Filipino Quiz #2.

课后,我继续编码,直到得到正确的编码,我才停下来。 因此,这是我的菲律宾认证测验2。

Image for post
Certified Filipino Quiz #2
菲律宾认证测验#2

This code is more user-friendly as what my caption states (promised!). In this code, I only use one text cell and one code cell to write the codes for my quiz. The major improvement was writing my questions in one list (and not using text cells. Yey!). Then a “for loop” to check the answers, and used “if-else” to evaluate the score. I also tried making a function “intro” though it is unnecessary.

正如我的标题所述(承诺!),此代码对用户更友好。 在此代码中,我仅使用一个文本单元格和一个代码单元格来编写我的测验代码。 最大的改进是将我的问题写在一个列表中(而不是使用文本单元格。是的!)。 然后使用“ for循环”检查答案,并使用“ if-else”评估分数。 我也尝试过使函数“入门”,尽管这是不必要的。

However, I saw one problem — What if the quiz taker will keep answering in the wrong format?

但是,我看到一个问题-如果测验者将继续以错误的格式回答该怎么办?

Thus, I made a Certified Filipino Quiz #3. This version will keep pushing you to try again and answer properly before moving on to the next question.

因此,我进行了菲律宾认证测验#3。 此版本将继续促使您再次尝试并正确回答,然后再继续下一个问题。

Image for post
Image for post
Certified Filipino Quiz #3
菲律宾认证测验#3

The differences it has with my version #2 have improved the code’s readability by adding comments, take out the unnecessary function “intro”, and most importantly the additional “while loop”. With the added “while loop”, the user should only type a “yes” or “no”. And this code will not quit until you answer properly.

它与我的版本2的不同之处在于,通过添加注释,删除了不必要的功能“简介”以及最重要的是附加的“ while循环”,提高了代码的可读性。 使用添加的“ while循环”,用户仅应键入“是”或“否”。 在您正确回答之前,此代码不会退出。

And there you have it! I’ve successfully made a Python Quiz.

在那里,您拥有了! 我已经成功完成了Python测验。

Next, what will happen if I rewrite my code in the Spyder IDE?

接下来,如果我在Spyder IDE中重写代码会怎样?

Spyder中的Python-不可能! (A Python in Spyder — Impossible!)

That’s supposed to be a joke but never mind.

那应该是个玩笑,但没关系。

To rewrite my code from Colab to Spyder, I just did a simple copy-and-paste.

要将我的代码从Colab重写到Spyder,我只做了一个简单的复制粘贴。

Image for post
Certified Filipino Quiz #3 in Spyder
Spyder认证菲律宾测验3

Then, I run the code.

然后,我运行代码。

Image for post
Run — Certified Filipino Quiz #3 in Spyder
运行-在Spyder中获得认证的菲律宾测验#3

Tada! My code from Colab still works here in Spyder but if you look closely, a lot of warning signs appeared in the editor pane. It’s because I enabled the code style linting to conform to PEP 8 convention. If you want to enable yours as well, just go to “Preferences” then under the “Completion and Linting” option, go to ”Code Style” tab and click the “Enable Code Style Linting”

多田我来自Colab的代码仍然可以在Spyder中使用,但是如果仔细观察,编辑器窗格中会出现许多警告标志。 这是因为我启用了代码样式棉绒以使其符合PEP 8约定。 如果您也想启用自己的功能,只需转到“首选项”,然后在“完成和添加”选项下,转到“代码样式”标签,然后单击“启用代码样式添加”

Image for post
PEP 8 Convention — Enabled
PEP 8惯例—已启用

For me, this is one of the main features here in Spyder that you can’t have in Colab. It strictly checks if your indents, code line length, etc. follow the PEP 8 convention to improve the readability of your code. It’s perfect too if you’re an OC like me.

对我来说,这是Spyder的主要功能之一,而Colab是您无法拥有的。 它严格检查您的缩进,代码行长等是否遵循PEP 8约定以提高代码的可读性。 如果您是像我这样的OC,也非常完美。

Unlike in Colab, which only has one window where you can both code and run your code, Spyder’s default workspace have three — editor, console, and variable explorer.

与Colab中只有一个可以同时编写代码和运行代码的窗口不同,Spyder的默认工作区具有三个-编辑器,控制台和变量资源管理器。

Image for post
Spyder’s default workspace window
Spyder的默认工作区窗口

Generally, Spyder and Colab are both IDE for Python but both designed for a different purpose. Colab, from the name itself, is done online and used by people who would love to collaborate and work together in coding. Colab is also favorable for Data Science because it has more packages that can do visualization tools than Spyder. While Spyder is designed for development such as apps, websites, etc.

通常,Spyder和Colab都是Python的IDE,但都是为不同的目的而设计的。 顾名思义,Colab是在线完成的,并由愿意在编码中进行协作和合作的人们使用。 Colab对Data Science也是有利的,因为与Spyder相比,它具有更多可以执行可视化工具的软件包。 尽管Spyder是为开发而设计的,例如应用程序,网站等。

And that’s all for now. I hope you’d get a thing or two from my coding experience. Also, please try to answer my #CertifiedFilipino Quiz cause I would really love to hear your comments and help me improve my skills.

到此为止。 希望您能从我的编码经验中受益。 另外,请尝试回答我的#CertifiedFilipino测验,因为我真的很想听听您的意见并帮助我提高技能。

print(“Thank you very much!”)

打印(“非常感谢!”)

Image for post
Photo by Jon Tyson on Unsplash
乔恩·泰森( Jon Tyson)Unsplash

翻译自: https://medium.com/swlh/how-certifiedfilipino-are-you-7ef60d77bb8b

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值