# how to make a function recursive

Filed under:
|
|
|
##### python-3.x

i have this huge function and i am wondering how to make it recursive. i have the base case which should never come true, so it should always go to else and keep calling itself with the variable t increases. any help would be great thanks

``````def draw(x, y, t, planets):
if 'Satellites' in planets["Moon"]:
else:
while True:
print("refresh")
print("colour 0 0 0")
print("clear")
print("colour 255 255 255")
if "Mercury" in planets:
print("circle",x,y,r_Mercury)
r_Xmer=x+math.sin(t*2*math.pi/planets['Mercury']['Period'])*r_Mercury
r_Ymer=y+math.cos(t*2*math.pi/planets['Mercury']['Period'])*r_Mercury
print("fillcircle",r_Xmer,r_Ymer,3)
if "Venus" in planets:
print("circle",x,y,r_Venus)
r_Xven=x+math.sin(t*2*math.pi/planets['Venus']['Period'])*r_Venus
r_Yven=y+math.cos(t*2*math.pi/planets['Venus']['Period'])*r_Venus
print("fillcircle",r_Xven,r_Yven,3)
if "Earth" in planets:
print("circle",x,y,r_Earth)
r_Xe=x+math.sin(t*2*math.pi/planets['Earth']['Period'])*r_Earth
r_Ye=y+math.cos(t*2*math.pi/planets['Earth']['Period'])*r_Earth
print("fillcircle",r_Xe,r_Ye,3)
if "Moon" in planets:
print("circle",r_Xe,r_Ye,r_Moon)
r_Xm=r_Xe+math.sin(t*2*math.pi/planets['Moon']['Period'])*r_Moon
r_Ym=r_Ye+math.cos(t*2*math.pi/planets['Moon']['Period'])*r_Moon
print("fillcircle",r_Xm,r_Ym,3)
if "Mars" in planets:
print("circle",x,y,r_Mars)
r_Xmar=x+math.sin(t*2*math.pi/planets['Mars']['Period'])*r_Mars
r_Ymar=y+math.cos(t*2*math.pi/planets['Mars']['Period'])*r_Mars
print("fillcircle",r_Xmar,r_Ymar,3)
if "Phobos" in planets:
print("circle",r_Xmar,r_Ymar,r_Phobos)
r_Xpho=r_Xmar+math.sin(t*2*math.pi/planets['Phobos']['Period'])*r_Phobos
r_Ypho=r_Ymar+math.cos(t*2*math.pi/planets['Phobos']['Period'])*r_Phobos
print("fillcircle",r_Xpho,r_Ypho,3)
if "Deimos" in planets:
print("circle",r_Xmar,r_Ymar,r_Deimos)
r_Xdei=r_Xmar+math.sin(t*2*math.pi/planets['Deimos']['Period'])*r_Deimos
r_Ydei=r_Ymar+math.cos(t*2*math.pi/planets['Deimos']['Period'])*r_Deimos
print("fillcircle",r_Xdei,r_Ydei,3)
if "Ceres" in planets:
print("circle",x,y,r_Ceres)
r_Xcer=x+math.sin(t*2*math.pi/planets['Ceres']['Period'])*r_Ceres
r_Ycer=y+math.cos(t*2*math.pi/planets['Ceres']['Period'])*r_Ceres
print("fillcircle",r_Xcer,r_Ycer,3)
if "Jupiter" in planets:
print("circle",x,y,r_Jupiter)
r_Xjup=x+math.sin(t*2*math.pi/planets['Jupiter']['Period'])*r_Jupiter
r_Yjup=y+math.cos(t*2*math.pi/planets['Jupiter']['Period'])*r_Jupiter
print("fillcircle",r_Xjup,r_Yjup,3)
if "Io" in planets:
print("circle",r_Xjup,r_Yjup,r_Io)
r_Xio=r_Xjup+math.sin(t*2*math.pi/planets['Io']['Period'])*r_Io
r_Yio=r_Yjup+math.cos(t*2*math.pi/planets['Io']['Period'])*r_Io
print("fillcircle",r_Xio,r_Yio,3)
if "Europa" in planets:
print("circle",r_Xjup,r_Yjup,r_Europa)
r_Xeur=r_Xjup+math.sin(t*2*math.pi/planets['Europa']['Period'])*r_Europa
r_Yeur=r_Yjup+math.cos(t*2*math.pi/planets['Europa']['Period'])*r_Europa
print("fillcircle",r_Xeur,r_Yeur,3)
if "Ganymede" in planets:
print("circle",r_Xjup,r_Yjup,r_Ganymede)
r_Xgan=r_Xjup+math.sin(t*2*math.pi/planets['Ganymede']['Period'])*r_Ganymede
r_Ygan=r_Yjup+math.cos(t*2*math.pi/planets['Ganymede']['Period'])*r_Ganymede
print("fillcircle",r_Xgan,r_Ygan,3)
if "Callisto" in planets:
print("circle",r_Xjup,r_Yjup,r_Callisto)
r_Xcal=r_Xjup+math.sin(t*2*math.pi/planets['Callisto']['Period'])*r_Callisto
r_Ycal=r_Yjup+math.cos(t*2*math.pi/planets['Callisto']['Period'])*r_Callisto
print("fillcircle",r_Xcal,r_Ycal,3)
if "Saturn" in planets:
print("circle",x,y,r_Saturn)
r_Xsat=x+math.sin(t*2*math.pi/planets['Saturn']['Period'])*r_Saturn
r_Ysat=y+math.cos(t*2*math.pi/planets['Saturn']['Period'])*r_Saturn
print("fillcircle",r_Xsat,r_Ysat,3)
if "Mimas" in planets:
print("circle",r_Xsat,r_Ysat,r_Mimas)
r_Xmim=r_Xsat+math.sin(t*2*math.pi/planets['Mimas']['Period'])*r_Mimas
r_Ymim=r_Ysat+math.cos(t*2*math.pi/planets['Mimas']['Period'])*r_Mimas
print("fillcircle",r_Xmim,r_Ymim,3)
print("fillcircle",r_Xenc,r_Yenc,3)
if "Tethys" in planets:
print("circle",r_Xsat,r_Ysat,r_Tethys)
r_Xtet=r_Xsat+math.sin(t*2*math.pi/planets['Tethys']['Period'])*r_Tethys
r_Ytet=r_Ysat+math.cos(t*2*math.pi/planets['Tethys']['Period'])*r_Tethys
print("fillcircle",r_Xtet,r_Ytet,3)
if "Dione" in planets:
print("circle",r_Xsat,r_Ysat,r_Dione)
r_Xdio=r_Xsat+math.sin(t*2*math.pi/planets['Dione']['Period'])*r_Dione
r_Ydio=r_Ysat+math.cos(t*2*math.pi/planets['Dione']['Period'])*r_Dione
print("fillcircle",r_Xdio,r_Ydio,3)
if "Rhea" in planets:
print("circle",r_Xsat,r_Ysat,r_Rhea)
r_Xrhe=r_Xsat+math.sin(t*2*math.pi/planets['Rhea']['Period'])*r_Rhea
r_Yrhe=r_Ysat+math.cos(t*2*math.pi/planets['Rhea']['Period'])*r_Rhea
print("fillcircle",r_Xrhe,r_Yrhe,3)
if "Titan" in planets:
print("circle",r_Xsat,r_Ysat,r_Titan)
r_Xtit=r_Xsat+math.sin(t*2*math.pi/planets['Titan']['Period'])*r_Titan
r_Ytit=r_Ysat+math.cos(t*2*math.pi/planets['Titan']['Period'])*r_Titan
print("fillcircle",r_Xtit,r_Ytit,3)
if "Iapetus" in planets:
print("circle",r_Xsat,r_Ysat,r_Iapetus)
r_Xiap=r_Xsat+math.sin(t*2*math.pi/planets['Iapetus']['Period'])*r_Iapetus
r_Yiap=r_Ysat+math.cos(t*2*math.pi/planets['Iapetus']['Period'])*r_Iapetus
print("fillcircle",r_Xiap,r_Yiap,3)
if "Uranus" in planets:
print("circle",x,y,r_Uranus)
r_Xura=x+math.sin(t*2*math.pi/planets['Uranus']['Period'])*r_Uranus
r_Yura=y+math.cos(t*2*math.pi/planets['Uranus']['Period'])*r_Uranus
print("fillcircle",r_Xura,r_Yura,3)
if "Puck" in planets:
print("circle",r_Xura,r_Yura,r_Puck)
r_Xpuc=r_Xura+math.sin(t*2*math.pi/planets['Puck']['Period'])*r_Puck
r_Ypuc=r_Yura+math.cos(t*2*math.pi/planets['Puck']['Period'])*r_Puck
print("fillcircle",r_Xpuc,r_Ypuc,3)
if "Miranda" in planets:
print("circle",r_Xura,r_Yura,r_Miranda)
r_Xmira=r_Xura+math.sin(t*2*math.pi/planets['Miranda']['Period'])*r_Miranda
r_Ymira=r_Yura+math.cos(t*2*math.pi/planets['Miranda']['Period'])*r_Miranda
print("fillcircle",r_Xmira,r_Ymira,3)
if "Ariel" in planets:
print("circle",r_Xura,r_Yura,r_Ariel)
r_Xari=r_Xura+math.sin(t*2*math.pi/planets['Ariel']['Period'])*r_Ariel
r_Yari=r_Yura+math.cos(t*2*math.pi/planets['Ariel']['Period'])*r_Ariel
print("fillcircle",r_Xari,r_Yari,3)
if "Umbriel" in planets:
print("circle",r_Xura,r_Yura,r_Umbriel)
r_Xumb=r_Xura+math.sin(t*2*math.pi/planets['Umbriel']['Period'])*r_Umbriel
r_Yumb=r_Yura+math.cos(t*2*math.pi/planets['Umbriel']['Period'])*r_Umbriel
print("fillcircle",r_Xumb,r_Yumb,3)
if "Titania" in planets:
print("circle",r_Xura,r_Yura,r_Titania)
r_Xtita=r_Xura+math.sin(t*2*math.pi/planets['Titania']['Period'])*r_Titania
r_Ytita=r_Yura+math.cos(t*2*math.pi/planets['Titania']['Period'])*r_Titania
print("fillcircle",r_Xtita,r_Ytita,3)
if "Oberon" in planets:
print("circle",r_Xura,r_Yura,r_Oberon)
r_Xober=r_Xura+math.sin(t*2*math.pi/planets['Oberon']['Period'])*r_Oberon
r_Yober=r_Yura+math.cos(t*2*math.pi/planets['Oberon']['Period'])*r_Oberon
print("fillcircle",r_Xober,r_Yober,3)
if "Neptune" in planets:
print("circle",x,y,r_Neptune)
r_Xnep=x+math.sin(t*2*math.pi/planets['Neptune']['Period'])*r_Neptune
r_Ynep=y+math.cos(t*2*math.pi/planets['Neptune']['Period'])*r_Neptune
print("fillcircle",r_Xnep,r_Ynep,3)
if "Titan" in planets:
print("circle",r_Xnep,r_Ynep,r_Titan)
r_Xtita=r_Xnep+math.sin(t*2*math.pi/planets['Titan']['Period'])*r_Titan
r_Ytita=r_Ynep+math.cos(t*2*math.pi/planets['Titan']['Period'])*r_Titan
print("fillcircle",r_Xtita,r_Ytita,3)

t += 0.003

print(draw(x, y, t, planets))
``````

© Stack Overflow or respective owner

• #### unmet dependencies in Ubuntu 12.04

I tried today to install a dvb-card on my Ubuntu 12.04 (Linux blauhai-linux 3.2.0-25-generic #40-Ubuntu SMP Wed May 23 20:30:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux ). The installation failed with an error. After that, i tried to install python (it was already installed but i got this error): linux:~\$… >>> More

• #### How can I get sikuli-ide to work?

I installed sikuli-ide with sudo apt-get install sikuli-ide Everything was fine until I tried to start it from the terminal. I typed sikuli-ide But the only response I got was [info] locale: en_US The application was not started, furthermore there is no desktop file and sikuli-ide does not… >>> More

• #### Getting PATH right for python after MacPorts install

as seen on Super User - Search for 'Super User'
I can't import some python libraries (PIL, psycopg2) that I just installed with MacPorts. I looked through these forums, and tried to adjust my PATH variable in \$HOME/.bash_profile in order to fix this but it did not work. I added the location of PIL and psycopg2 to PATH. I know that Terminal is… >>> More

• #### call python with system() in R to run a python script emulating the python console

as seen on Stack Overflow - Search for 'Stack Overflow'
I want to pass a chunk of Python code to Python in R with something like system('python ...'), and I'm wondering if there is an easy way to emulate the python console in this case. For example, suppose the code is "print 'hello world'", how can I get the output like this in R? >>> print… >>> More

• #### Python - Calling a non python program from python?

as seen on Stack Overflow - Search for 'Stack Overflow'
Hi, I am currently struggling to call a non python program from a python script. I have a ~1000 files that when passed through this C++ program will generate ~1000 outputs. Each output file must have a distinct name. The command I wish to run is of the form: program_name -input -output -o1 -o2… >>> More

• #### MAMP + Python MySQLDB - trouble installing

as seen on Server Fault - Search for 'Server Fault'
I'm currently running the latest version of MAMP on my Snow Leopard OSX, and I'm trying to install MySQLDB. Downloaded: MySQL-python-1.2.3c1 I went into the setup_posix.py and adjusted the location of the mysql_config to the one in MAMP: mysql_config.path = "/Applications/MAMP/Library/bin/mysql_config" When… >>> More

• #### Compiling a program with a legacy version of gcc

as seen on Stack Overflow - Search for 'Stack Overflow'
This is probably a very difficult problem to troubleshoot with the information I can practically provide, but I'm hoping someone might be able to at least point me in a possible direction. I'm trying to install HTK (http://htk.eng.cam.ac.uk/), which, according to this page needs to be installed using… >>> More

• #### eventmachine on debian fails install via rubygems

as seen on Stack Overflow - Search for 'Stack Overflow'
this has been killing me for the last 5 hours. I don't seem to be able to get eventmachine running on my debian box. here this output: \$ gem install thin Building native extensions. This could take a while... ERROR: Error installing thin: ERROR: Failed to build gem native extension. … >>> More

• #### Can overloading is possible with two version of function, constant member function and function with

as seen on Stack Overflow - Search for 'Stack Overflow'
Hello, I just came across various overloading methods like type of parameter passed, varying number of parameters, return type etc. I just want to know that can I overload a function with following two version //function which can modify member String& MyClass::doSomething(); //constant member… >>> More

• #### [PHP] function().function() VS function()function()

as seen on Stack Overflow - Search for 'Stack Overflow'
Hi all, I was writing a foreach Loop in PHP5. Here is the script: foreach(range('A','Z') as \$char) // line 1 { // line 2 echo strtoupper(\$char)strtolower(\$char); // line 3 } // line 4 And I got this error message Parse error: parse error, unexpected T_STRING in testing.php on line 3 I spent almost… >>> More