Kir*_*ers 7 python loops while-loop
我还在学习Python,因为我想向十一岁的孩子讲授这门语言的基本概念(我是一名教师).我们在基础方面做了一些工作,因此他们了解编程的基本要素,并将任务分解成块等.Python是那将是所有教在英国新课程进来,我不想教孩子坏习惯的语言.下面是我写的一个小程序,是的,我知道它很糟糕,但任何有关改进的建议都会非常感激.
我仍在翻阅语言的教程,所以请保持温和!: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")
Run Code Online (Sandbox Code Playgroud)
Joh*_*ooy 10
您似乎不需要变量 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
Run Code Online (Sandbox Code Playgroud)