Hey there! Sign in to join this conversationNew here? Join for free
    • TSR Support Team
    • Study Helper
    Offline

    20
    ReputationRep:
    (Original post by will'o'wisp2)
    nope i can't get it to work either
    https://cdn.discordapp.com/attachmen...11/unknown.png
    This is looking better but I think your second return statement shouldn't be indented. There's another mistake but try this first.
    • Offline

      20
      (Original post by DFranklin)
      There's a "don't post full solutions" rule for this forum.
      It isn't a full solution though, because OP obviously isn't after something like this.
      Online

      17
      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?
      Offline

      21
      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?
      Wat?

      This is university work? 0_0
      • TSR Support Team
      • Study Helper
      Offline

      20
      ReputationRep:
      (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

      18
      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]
      Online

      17
      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

      18
      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

      19
      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.
      • TSR Support Team
      • Study Helper
      Offline

      20
      ReputationRep:
      (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 :/
      • TSR Support Team
      • Study Helper
      Offline

      20
      ReputationRep:
      (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
      • TSR Support Team
      • Study Helper
      Offline

      20
      ReputationRep:
      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 .__.
      • TSR Support Team
      • Study Helper
      Offline

      20
      ReputationRep:
      (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
     
     
     
  1. See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  2. Poll
    What newspaper do you read/prefer?
    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
  3. See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  4. 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

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