Turn on thread page Beta
    Offline

    18
    ReputationRep:
    (Original post by will'o'wisp2)
    So i need to be able to write using recursion

    ~snip~

    i need help on the above topics i'm not realyl sure where to start
    I'm going to be harsh here, but I think this needs to be said.

    It doesn't seem like you know even the absolute basics (about recursion or Python) that would enable you to do this properly.

    This is far from the only time you've posted on here for help with a question without seeming to actually know anything about the topic.

    The truth is, you may be able to work your way through to an answer like this, but without actually studying the underlying material,you're going to end up in a real mess eventually.

    Are you actually attending all the relevant lectures?
    • Community Assistant
    Online

    21
    ReputationRep:
    Community Assistant
    (Original post by DFranklin)
    I'm going to be harsh here, but I think this needs to be said.

    It doesn't seem like you know even the absolute basics (about recursion or Python) that would enable you to do this properly.

    This is far from the only time you've posted on here for help with a question without seeming to actually know anything about the topic.

    The truth is, you may be able to work your way through to an answer like this, but without actually studying the underlying material,you're going to end up in a real mess eventually.

    Are you actually attending all the relevant lectures?
    Wat?

    This is university work? 0_0
    • Community Assistant
    • Study Helper
    Offline

    20
    ReputationRep:
    Community Assistant
    Study Helper
    (Original post by FriendlyPenguin)
    In that example, a is a global variable. It is defined after the function is defined, but before the function is called.
    Yes that was stupid of me. I was expecting two parameters in the function so was focussing on that.
    • Thread Starter
    Offline

    15
    ReputationRep:
    (Original post by Notnek)
    This is looking better but I think your second return statement shouldn't be indented. There's another mistake but try this first.
    https://cdn.discordapp.com/attachmen...86/unknown.png

    i don't think 7 is what i'm looking for i was looking for 6=3x2
    Offline

    20
    ReputationRep:
    (Original post by will'o'wisp2)
    So i need to be able to write using recursion

    multiplication using addition
    powers using multiplication
    factorials and
    the fibonacci sequence

    so far i know that you layout roughly in this form of

    def fib(n)
    a=............
    b=............
    return ...... <- is the nth term

    print(fib(2))

    def main()

    then you got your function whatnot but i need help on the above topics i'm not realyl sure where to start
    An example of the start of the fibonnachi one:

    def fib(n)
    If n=0
    Return 0
    [edited]
    Offline

    18
    ReputationRep:
    (Original post by TheMindGarage)
    An example of the fibonnachi one:
    ~snip~
    This forum has a rule against posting full solutions.
    • Thread Starter
    Offline

    15
    ReputationRep:
    (Original post by DFranklin)
    I'm going to be harsh here, but I think this needs to be said.

    It doesn't seem like you know even the absolute basics (about recursion or Python) that would enable you to do this properly.

    This is far from the only time you've posted on here for help with a question without seeming to actually know anything about the topic.

    The truth is, you may be able to work your way through to an answer like this, but without actually studying the underlying material,you're going to end up in a real mess eventually.

    Are you actually attending all the relevant lectures?
    Yup, i've been to every single computational lecture. We do some practicals and we get given sheets on how to go through it all but the recursion sheet althought it doesn't have much on recursion it keeps implying that i need to use the if statement but i don't know how to stick that in there, i mean i can do a simple multiplication

    just do

    def multiply(a,b)
    return a*b

    print(3,4) and you can get 12 but i don't know how to stick an if statement in, so far if i use something like the sheet tells me i get factorial code not multiplication in terms of addition so i don't know :/
    Offline

    20
    ReputationRep:
    (Original post by DFranklin)
    This forum has a rule against posting full solutions.
    Sorry - didn't know that posting a full solution to one of the parts was against the rules. Edited.
    Offline

    21
    ReputationRep:
    (Original post by Blue_Cow)
    Wat?

    This is university work? 0_0
    Trust me. Recursions are A-level content, though this doesn't mean OP is not at uni.
    • Community Assistant
    • Study Helper
    Offline

    20
    ReputationRep:
    Community Assistant
    Study Helper
    (Original post by will'o'wisp2)
    https://cdn.discordapp.com/attachmen...86/unknown.png

    i don't think 7 is what i'm looking for i was looking for 6=3x2
    What is your code actually doing?

    multiply(3) = 3 + multiply(2)
    multiply(2) = 3 + multiply(1)
    multiply(1) = 1

    So multiply(3) = 3 + (3 + 1) = 7

    But that's not what you want. There's a simple fix for this.
    • Thread Starter
    Offline

    15
    ReputationRep:
    (Original post by TheMindGarage)
    An example of the start of the fibonnachi one:

    def fib(n)
    If n=0
    Return 0
    [edited]
    i know how to do fib specifically
    just establish 2 base cases and carry on with life as normal
    https://cdn.discordapp.com/attachmen...60/unknown.png

    like that
    • Thread Starter
    Offline

    15
    ReputationRep:
    (Original post by Notnek)
    What is your code actually doing?

    multiply(3) = 3 + multiply(2)
    multiply(2) = 3 + multiply(1)
    multiply(1) = 1

    So multiply(3) = 3 + (3 + 1) = 7

    But that's not what you want. There's a simple fix for this.
    i think so, so probably so

    if n==1
    return 0

    but that online one i was using just broke :/
    • Community Assistant
    • Study Helper
    Offline

    20
    ReputationRep:
    Community Assistant
    Study Helper
    (Original post by will'o'wisp2)
    i think so, so probably so

    if n==1
    return 0

    but that online one i was using just broke :/
    What would multiply(3) give you with this change?
    • Thread Starter
    Offline

    15
    ReputationRep:
    (Original post by Notnek)
    What would multiply(3) give you with this change?
    https://cdn.discordapp.com/attachmen...47/unknown.png
    6
    • Community Assistant
    • Study Helper
    Offline

    20
    ReputationRep:
    Community Assistant
    Study Helper
    I assume that's not what you want though? I'm guessing your multiply function is meant to multiply the input by 3.

    So multiply(3) should equal 9...
    • Thread Starter
    Offline

    15
    ReputationRep:
    (Original post by Notnek)
    I assume that's not what you want though? I'm guessing your multiply function is meant to multiply the input by 3.

    So multiply(3) should equal 9...
    https://cdn.discordapp.com/attachmen...88/unknown.png

    i've done this but i don't think it's recursion .__.
    • Community Assistant
    • Study Helper
    Offline

    20
    ReputationRep:
    Community Assistant
    Study Helper
    (Original post by will'o'wisp2)
    https://cdn.discordapp.com/attachmen...88/unknown.png

    i've done this but i don't think it's recursion .__.
    a+a(b-1) = a(1 + b - 1) = ab

    So all that function is doing is returning a\times b which is why it works. It is not using recursion.

    I think you should fix your last attempt because you were close. Then you can extend it to multiply(a,b).
    • Thread Starter
    Offline

    15
    ReputationRep:
    (Original post by Notnek)
    I assume that's not what you want though? I'm guessing your multiply function is meant to multiply the input by 3.

    So multiply(3) should equal 9...
    but no i want it to multiply by the previuos number so if i stick 5 in i want 5x4 to come out

    then again i'm not sure how i'd do recursion with any 2 numbers
    • Community Assistant
    Online

    21
    ReputationRep:
    Community Assistant
    (Original post by will'o'wisp2)
    https://cdn.discordapp.com/attachmen...88/unknown.png

    i've done this but i don't think it's recursion .__.
    You're right. That's not recursion.

    There is not a single a line of code that makes the function call itself.

    Once you've done this, I suggest trying to learn Haskell. That will force you to do/learn recursion properly.
    • Community Assistant
    • Study Helper
    Offline

    20
    ReputationRep:
    Community Assistant
    Study Helper
    (Original post by will'o'wisp2)
    but no i want it to multiply by the previuos number so if i stick 5 in i want 5x4 to come out

    then again i'm not sure how i'd do recursion with any 2 numbers
    Do you mean that you want it to multply the previous number by 3?

    I'm not sure why you want it to do this. I recommend making a function that outputs 3 x n if you input n. Then you can extend this to a multiply(a,b) function.
 
 
 
Reply
Submit reply
Turn on thread page Beta
Updated: November 5, 2017

University open days

  1. University of Bradford
    University-wide Postgraduate
    Wed, 25 Jul '18
  2. University of Buckingham
    Psychology Taster Tutorial Undergraduate
    Wed, 25 Jul '18
  3. Bournemouth University
    Clearing Campus Visit Undergraduate
    Wed, 1 Aug '18
Poll
How are you feeling in the run-up to Results Day 2018?
Useful resources

Make your revision easier

Maths

Maths Forum posting guidelines

Not sure where to post? Read the updated guidelines here

Equations

How to use LaTex

Writing equations the easy way

Student revising

Study habits of A* students

Top tips from students who have already aced their exams

Study Planner

Create your own Study Planner

Never miss a deadline again

Polling station sign

Thinking about a maths degree?

Chat with other maths applicants

Can you help? Study help unanswered threads

Groups associated with this forum:

View associated groups

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.