Recursion

BabbleDay posted @ 2015年7月01日 03:57 in 刷题防身 with tags composingprograms.com recursion python , 680 阅读

ComposingPrograms 1.7 Exercises

 

def countdown(n):
    print(n)
    if n>1:
        countdown(n-1)

def countup(n):
    if n>0:
        countup(n-1)
        print(n)

def recursive(m,n):
    if n>0:
        return m + recursive(m, n-1)
    else:
        return 0

def expt(base, power):
    if power==0:
        return 1
    else:
        return base * expt(base, power-1)

def sum_digits(n):
    if n<10:
        return n
    else:
        return n%10 + sum_digits(n//10)

def is_prime(n, d):
    if n<=1:
        return False
    elif d==1:
        return True
    elif n%d==0:
        return False
    else:
        return is_prime(n, d-1)

def sum_primes_up_to(n):
    if n==2:
        return 2
    elif is_prime(n, n-1):
        return sum_primes_up_to(n-1) + n
    else:
        return sum_primes_up_to(n-1)
Avatar_small
delete hotmail accou 说:
2019年6月04日 15:28

It was better than previous. I like it very much.

Avatar_small
Oasis scholarship st 说:
2022年8月03日 06:54

The department of tribal development and the backward classes welfare department of West Bengal has initiated the Oasis Scholarship for the students of the backward class category. This Online Application for Scholarship in Studies (OASIS) will be provided to Scheduled caste, Oasis scholarship status check The department of tribal development and the backward classes welfare department of West Bengal has initiated the Oasis Scholarship for the students of the backward class category. Scheduled Tribe, and OBC category students based on their merit marks. Students up to PG are eligible including those who register for West Bengal employment bank enrollment, but as a student of the course as per eligibility.

Avatar_small
CBSE sa 1 Sample Pap 说:
2022年9月27日 21:05

The Summative Assessment -1 Exams are known as Half Yearly (6 Months) Exams and it’s held also as Term-1 exams for all grade students. Every student can download the CBSE Class 5 SA-1 Sample Paper 2023 Pdf or Term-1 Question Bank that covers all topics chapter by chapter for all languages & subjects of the course. CBSE sa 1 Sample Paper Class 5 The teaching staff of the school along with subject experts of the board have introduced the CBSE 5th Class SA-1 Sample Paper 2023 with suggested answer solutions for all format exams.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter