Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    15
    ReputationRep:
    https://cdn.discordapp.com/attachmen...8/Untitled.png

    is me at the bottom


    anyway
    https://cdn.discordapp.com/attachmen...92/unknown.png

    can you replace base and exp with any 2 variable here for example a and b?

    https://cdn.discordapp.com/attachmen...40/unknown.png

    So a here is clearly incorrect. The reason stated in the answers was that "print does not store a variable and therefore we will get an error" so then does the command "return" store variables then?

    https://cdn.discordapp.com/attachmen...96/unknown.png

    im not quite understand the part about the arguments bits. So i know an argument is something like an undefined letter like a or something like that when you define something but i don't get the defined argument before non defined argument bit?
    Online

    17
    ReputationRep:
    These are really pure coding questions with no math content. You would be better posting in https://www.thestudentroom.co.uk/forumdisplay.php?f=119
    Online

    17
    ReputationRep:
    (Original post by DFranklin)
    These are really pure coding questions with no math content. You would be better posting in https://www.thestudentroom.co.uk/forumdisplay.php?f=119
    Replying to myself to say I checked the activity on that forum and it seems very dead. So although the Maths forum isn't really the "right" forum, you are probably better off posting here, but do please bear in mind that your posts are strictly speaking off topic.
    Online

    17
    ReputationRep:
    (Original post by will'o'wisp2)
    https://cdn.discordapp.com/attachmen...92/unknown.png

    can you replace base and exp with any 2 variable here for example a and b?
    Yes.
    https://cdn.discordapp.com/attachmen...40/unknown.png

    So a here is clearly incorrect. The reason stated in the answers was that "print does not store a variable and therefore we will get an error" so then does the command "return" store variables then?
    I don't really like the given answer.

    It seems to me the point here is that a(n) needs to return a value. (If you are unclear about what "return" means, I would think of it as "you call the function a, with parameter n, and the result of that function is what is returned".


    If you want to define a function recursively (so that it calls itself), then it needs to return the results when it is called (so you can use them).

    I think the discussion about "storing" results is a bit confusing in this context; there's a sense in which return does "store" results, but it's probably not the way most programmers would think of it.

    https://cdn.discordapp.com/attachmen...96/unknown.png

    im not quite understand the part about the arguments bits. So i know an argument is something like an undefined letter like a or something like that when you define something but i don't get the defined argument before non defined argument bit?
    So, suppose I define a function root(x = 3, r = 2) which returns \sqrt[r]{x}.

    If I call root(), it will put in the 2 default arguments, so it's as if I called root(3, 2) (so I get \sqrt[2]{3})
    If I call root(9), it puts in the last default argument, so it's as if I called root(9, 2). (so I get \sqrt[2]{9})

    And if I call root (9, 3), I just get \sqrt[3]{9}.

    Instead, I could have defined root(x, r = 2), in which case I always have to supply the value for x. So root() would not be allowed, but the other 2 cases would work fine.

    The point is, I can't do this the other way around, and define root(x=3, r). And it's basically because the syntax gets very confusing and ambiguous if you allow this.
 
 
 
Poll
Who is your favourite TV detective?
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.