小编cli*_*nMe的帖子

如何加速python的'乌龟'功能并最终阻止它冻结

我在python中编写了一个海龟程序,但有两个问题.

  1. 对于较大的数字来说,它太慢了,我很想知道如何加速龟.
  2. 它完成后点击时会冻结,说"没有回复"

到目前为止这是我的代码:

import turtle

#Takes user input to decide how many squares are needed
f=int(input("How many squares do you want?"))
c=int(input("What colour would you like? red = 1, blue = 2 and green =3"))
n=int(input("What background colour would you like? red = 1, blue = 2 and green =3"))

i=1

x=65

#Draws the desired number of squares.
while i < f:
    i=i+1
    x=x*1.05
    print ("minimise this window ASAP")
    if c==1:
        turtle.pencolor("red")
    elif c==2:
        turtle.pencolor("blue")
    elif c==3:
        turtle.pencolor("green")
    else: …
Run Code Online (Sandbox Code Playgroud)

python graphics draw turtle-graphics

19
推荐指数
2
解决办法
6万
查看次数

Python,将整数写入'.txt'文件

使用pickle函数是将整数写入文本文件的最快且最强大的方法吗?

这是我到目前为止的语法:

import pickle

pickle.dump(obj, file)
Run Code Online (Sandbox Code Playgroud)

如果有更强大的替代方案,请随时告诉我.

我的用例是写一个用户输入:

n=int(input("Enter a number: "))
Run Code Online (Sandbox Code Playgroud)
  • 是的,人类将需要阅读它并可能编辑它
  • 文件中将有10个数字
  • Python可能需要稍后再读.

python performance pickle robustness

8
推荐指数
2
解决办法
5万
查看次数