Lost Password?


Go Back   CodeCall Programming Forum > Software Development > Python

Python Discussion forum for Python, a high-level language with simple syntax, but yet powerful.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-19-2008, 11:01 AM
Xenofon Xenofon is offline
Newbie
 
Join Date: Sep 2008
Posts: 1
Rep Power: 0
Xenofon is on a distinguished road
Default Need help with 2 simple things

Hi, I just started learning programming and I was told that Python was good for beginners, and after solving just a few problems I'm already stuck...

I'm suppose to make a function that counts down from the number entered and then up again. Using recursion (if). I can make it go either up or down but not both in one function.

For example if i enter 4 it should do this:

4 3 2 1 0 1 2 3 4

The next problem is the same but using iteration (while) instead of recursion.

I know this must be so easy but the answer eludes me. Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 10-31-2008, 12:19 PM
manux manux is offline
Newbie
 
Join Date: Oct 2008
Posts: 26
Rep Power: 1
manux is on a distinguished road
Default Re: Need help with 2 simple things

you can give another argument in you recursive function that will specify if the counter should go up or down:

Quote:
Code:
def upAndDown(n, nmax , goingDown):
    print n
    if goingDown:
       if n>0:
           upAndDown(n-1,nmax,True)
       else:
           #etc...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Project: ionFiles - Joomla Simple File Download Jordan Community Projects 331 11-26-2008 12:35 PM
Probably a simple class question utdiscant Python 1 06-10-2008 10:10 PM
How to style fonts of a text in a simple page? c0de Tutorials 3 09-15-2007 11:08 PM
Simple PHP/MYSQL guide Jaan PHP Tutorials 0 01-07-2007 05:22 PM


All times are GMT -5. The time now is 08:25 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads