关于super() takes at least 1 argument (0 given)问题

1.python版本的问题,自身代码书写格式有误

      1) 在python2.x中,类的继承格式如下,函数super()需要两个实参:子类名和对象self。为帮助python将父类和子类联系起来,这两个参数必不可少。

       2) 在python3.x中,类的继承格式如下,函数super()不需要携带实参

      编写代码时注意自己要运行的版本,格式问题

2.编辑器没有配置正确的python环境

          我用的是sublime text,这个编辑器默认的python环境是2.x,即使你电脑上已经将默认python设置为了3.x,sublime运行python代码时依然匹配的是python2.x,所以需要在sublime中添加python3的运行环境(图中我已经添加好python3的环境了)

网上可以搜的到,把原链接放到这里记录下,侵删,这个是比较直观的,正好解决我的问题:https://blog.csdn.net/weixin_41768008/article/details/79859008

       1)   tools-->build system-->new build system

    2)出现如下图文件,更改文件内容

上图路径是你的python3 路径,保存,文件名python3.sublime-build

3)勾选运行环境,command+b运行你的程序即可:

-----------------------------------------------------------------------------------------------------------------------------

记录下我遇到的问题:

使用python3的格式来写类的继承,出现super() takes at least 1 argument (0 given)这样的问题

都说是因为我用python2来运行的,所以不正确,需要改格式,但是改了格式之后,又出现must be type, not classobj这样的问题

看有的帖子说继承那儿需要换一种写法,父类名.__init__(self,参数1,参数2),这样确实可以运行出来,但是原因现在我还不太清楚,研究明白之后再记录

这个时候我就想是不是sublime的问题,所以使用终端运行了使用python3写的继承代码,结果是成功的(macbook之前已经将python3设置为默认),说明就是我的su blime text 有问题,我没有添加python3的运行环境导致的,添加上就可以了

 

帮我写出以下java代码:Add a class Bubble that extends Shape. The Bubble class has an instance variable called radius of type double that represents the radius of the bubble. The constructor of the Bubble class takes an x and a y as arguments, which represent the position of the new bubble. The radius of a new bubble is always 10 and never changes after that. The isVisible method indicates whether the bubble is currently visible inside a window of width w and height h (position (0, 0) is in the upper-left corner of the window). The bubble is considered visible if at least one pixel of the bubble is visible. Therefore a bubble might be visible even when its center is outside the window, as long as the edge of the bubble is still visible inside the window. The code of the isVisible method is a little bit complex, mostly because of the case where the center of the circle is just outside one of the corners of the window. So here is the code of the isVisible method, which you can directly copy-paste into your assignment: // Find the point (wx, wy) inside the window which is closest to the // center (x, y) of the circle. In other words, find the wx in the // interval [0, w - 1] which is closest to x, and find the wy in the // interval [0, h - 1] which is closest to y. // If the distance between (wx, wy) and (x, y) is less than the radius // of the circle (using Pythagoras's theorem) then at least part of // the circle is visible in the window. // Note: if the center of the circle is inside the window, then (wx, wy) // is the same as (x, y), and the distance is 0. public boolean isVisible(int w, int h) { double x = getX(); double y = getY(); double wx = (x < 0 ? 0 : (x > w - 1 ? w - 1 : x)); double wy = (y < 0 ? 0 : (y > h - 1 ? h - 1 : y)); double dx = wx - x; double dy = wy - y; return dx * dx + dy * dy <= radius * radius; } The isIn method indicates whether the point at coordinates (x, y) (which are the arguments of the method) is currently inside the bubble or not. The edge of the bubble counts as being inside of the bubble. HINT: use Pythagoras's theorem to compute the distance from the center of the bubble to the point (x, y). The draw method uses the graphics object g to draw the bubble. HINT: remember that the color of the graphics object g is changed in the draw method of the superclass of Bubble. Also add a testBubble method to test all your methods (including inherited methods, but excluding the isVisible method, which I provide, and excluding the draw method since it requires as argument a graphics object g that you
最新发布
05-22
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值