Skip to content
Advertisement

Already updated my pip, still failed to add circle as a module

  1. I have been searching for different methods for using a class method to create circles. At first, I was able to print ‘c1’, however, after updating my python, it said is not defined which confuses me.
JavaScript
JavaScript

Is there any method that I can solve it or any recommended websites for such programming functions? Thank you.

Advertisement

Answer

There’s a few things wrong here. First off a class doesn’t take in any arguments, so instead of

JavaScript

it would just be

JavaScript

secondly you are using one underscore for __init__, so it’d be

JavaScript

also you aren’t setting the declared variables to anything, it needs to be this

JavaScript

it’s also best not to use capitals for variable names, so change R to r

you’ve also indented the c1, c2, c3 and c4 variables to be inside the class, it needs to be this

JavaScript

now you can print out c1. But c1 will just print out something like <__main__.circle object at 0x000001F89906A0A0> because you’re printing the object itself. If you want to print a specific value you use the . operator, so it’d be

JavaScript

that’d print the x0 variable

if you want to print them all you could use

JavaScript

is this something along the lines of what you’re going for?

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement