查找坐标时将Float解析为Int

2024-10-01 22:41:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我想画一幅中间有一个黑色圆圈的画。你知道吗

def Circle():
  pic=makeEmptyPicture(200,200)
  centre=(100,100)

  for y in range (0,200):
    for x in range (0,200):
      value =int[( 200/(100-y^2)^.5)]
      if  value!= 0 and x <=value:
        px=getPixel(pic,x,y)
        setColor(px, makeColor(0,0,0))

  return(pic)

我得到The error was: 'int' and 'float'

我不知道如何将value解析为int


Tags: andinforifvaluedefrangeint
2条回答
value =int[( 200/(100-y^2)^.5)]

像函数调用一样使用括号而不是方括号。而且^(按位异或)应该是**(指数)。你知道吗

value = int(200 / (100 - y**2) ** 0.5)

我的代码逻辑有缺陷:

def Circle():
  pic=makeEmptyPicture(200,200)
  r=20
  centre=(100,100)

  for y in range (0,200):
    for x in range (0,200):
      px=getPixel(pic,x,y)
      if (( pow((x-100),2)+pow((y-100),2))<pow(r,2)):

        setColor(px, makeColor(0,0,0))

  return(pic)

circle


我保留目前的答案,作为答案,因为它处理我的问题,我觉得有义务张贴一个替代解决我的问题。你知道吗

相关问题 更多 >

    热门问题