请代码检查我的示例Python程序 [英] Please code review my sample Python program

查看:78
本文介绍了请代码检查我的示例Python程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍在学习Python,因为我想向11岁的孩子(我是老师)教该语言的基本概念.我们已经在基础方面做了一些工作,以便他们了解编程的基本知识,并将任务分解为大块之类的东西.随着新课程的到来,Python将成为全英国要使用的语言,我不想教孩子们不良的习惯.下面是一个我编写的小程序,是的,我知道这很糟糕,但是任何有关改进的建议都将不胜感激.

I'm still learning Python as I want to teach the essential concepts of the language to eleven year old kids (I work as a teacher). We have done a bit of work in basic so they understand the essentials of programming and breaking down tasks into chunks and such like. Python is the language that is going to be taught all across the UK with the new curriculum coming in and I don't want to teach the kids bad habits. Below is a little program that I have written, yep I know it's bad but any advice about improvements would be very much appreciated.

我仍在努力学习该语言的教程,因此请保持温柔! :o)

I am still plowing through tutorials on the language so please be gentle! :o)

# This sets the condition of x for later use
x=0
# This is the main part of the program
def numtest():
    print ("I am the multiplication machine")
    print ("I can do amazing things!")
    c = input ("Give me a number, a really big number!")
    c=float(c)
    print ("The number", int(c), "multiplied by itself equals",(int(c*c)))
    print("I am Python 3. I am really cool at maths!")
    if (c*c)>10000:
        print ("Wow, you really did give me a big number!")
    else:
         print ("The number you gave me was a bit small though. I like bigger stuff than that!")

# This is the part of the program that causes it to run over and over again.
while x==0:
    numtest()
    again=input("Run again? y/n >>>")
    if x=="y":
        print("")
        numtest()
    else:
        print("Goodbye")

推荐答案

您似乎不需要变量x

while True:
    numtest()
    again = input("Run again? y/n >>>")
    if again == "y":       # test "again", not "x"
        print("")
    else:
        print("Goodbye")
        break              # This will exit the while loop

这篇关于请代码检查我的示例Python程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆