Compute the ratio of the sum of cube of the first 'n' natural numbers to the sum of square of first 'n' natural numbersWhy are Python lambdas useful?Convert a number range to another range, maintaining ratioPython progression path - From apprentice to guruTaking square of summed numbersFunction to calculate the difference between sum of squares and square of sumsWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?Sum of squares using lambda functionssum of squares of the first n odd numbersalgorithm to get power sum of natural numbersCompute cube root of extremely big number in Python3

What is the philosophical significance of speech acts/implicature?

How to stop co-workers from teasing me because I know Russian?

How to display Aura JS Errors Lightning Out

What happens to Mjolnir (Thor's hammer) at the end of Endgame?

How can I print the prosodic symbols in LaTeX?

What happened to Captain America in Endgame?

How can I practically buy stocks?

Which big number is bigger?

What makes accurate emulation of old systems a difficult task?

Alignment of various blocks in tikz

How to fry ground beef so it is well-browned

Pulling the rope with one hand is as heavy as with two hands?

Multiple options vs single option UI

"The cow" OR "a cow" OR "cows" in this context

Implications of cigar-shaped bodies having rings?

A ​Note ​on ​N!

Can we say “you can pay when the order gets ready”?

What is causing the white spot to appear in some of my pictures

As an international instructor, should I openly talk about my accent?

Was there a Viking Exchange as well as a Columbian one?

Is there a way to generate a list of distinct numbers such that no two subsets ever have an equal sum?

Can an Area of Effect spell cast outside a Prismatic Wall extend inside it?

How to prevent z-fighting in OpenSCAD?

Could the terminal length of components like resistors be reduced?



Compute the ratio of the sum of cube of the first 'n' natural numbers to the sum of square of first 'n' natural numbers


Why are Python lambdas useful?Convert a number range to another range, maintaining ratioPython progression path - From apprentice to guruTaking square of summed numbersFunction to calculate the difference between sum of squares and square of sumsWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?Sum of squares using lambda functionssum of squares of the first n odd numbersalgorithm to get power sum of natural numbersCompute cube root of extremely big number in Python3






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-4















Compute the ratio of the sum of cube of the first 'n' natural numbers to the sum of square of first 'n' natural numbers.



Code:



input_int=[x for x in range (1,input_int+1)]
python=reduce(lambda x,y:x+y **3/sum(input_int) % x +y**2/sum(input_int),input_int)
x=10


Solution output:



62.96363636363636


Expected output:



7.857142857142857









share|improve this question
























  • Please add some context to your question as well as formatting your code.

    – Tobias Wilfert
    Mar 9 at 8:18











  • You are only squaring and cubing the y .. for starters. Dividing through sum(input_int) makes no sense at all for your taks.

    – Patrick Artner
    Mar 9 at 9:41











  • Reads like a university/college/interview programming assignment...

    – dijksterhuis
    Mar 9 at 12:43

















-4















Compute the ratio of the sum of cube of the first 'n' natural numbers to the sum of square of first 'n' natural numbers.



Code:



input_int=[x for x in range (1,input_int+1)]
python=reduce(lambda x,y:x+y **3/sum(input_int) % x +y**2/sum(input_int),input_int)
x=10


Solution output:



62.96363636363636


Expected output:



7.857142857142857









share|improve this question
























  • Please add some context to your question as well as formatting your code.

    – Tobias Wilfert
    Mar 9 at 8:18











  • You are only squaring and cubing the y .. for starters. Dividing through sum(input_int) makes no sense at all for your taks.

    – Patrick Artner
    Mar 9 at 9:41











  • Reads like a university/college/interview programming assignment...

    – dijksterhuis
    Mar 9 at 12:43













-4












-4








-4








Compute the ratio of the sum of cube of the first 'n' natural numbers to the sum of square of first 'n' natural numbers.



Code:



input_int=[x for x in range (1,input_int+1)]
python=reduce(lambda x,y:x+y **3/sum(input_int) % x +y**2/sum(input_int),input_int)
x=10


Solution output:



62.96363636363636


Expected output:



7.857142857142857









share|improve this question
















Compute the ratio of the sum of cube of the first 'n' natural numbers to the sum of square of first 'n' natural numbers.



Code:



input_int=[x for x in range (1,input_int+1)]
python=reduce(lambda x,y:x+y **3/sum(input_int) % x +y**2/sum(input_int),input_int)
x=10


Solution output:



62.96363636363636


Expected output:



7.857142857142857






python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 9 at 9:30









Patrick Artner

27.2k62544




27.2k62544










asked Mar 9 at 8:16









Pradeep vPradeep v

1




1












  • Please add some context to your question as well as formatting your code.

    – Tobias Wilfert
    Mar 9 at 8:18











  • You are only squaring and cubing the y .. for starters. Dividing through sum(input_int) makes no sense at all for your taks.

    – Patrick Artner
    Mar 9 at 9:41











  • Reads like a university/college/interview programming assignment...

    – dijksterhuis
    Mar 9 at 12:43

















  • Please add some context to your question as well as formatting your code.

    – Tobias Wilfert
    Mar 9 at 8:18











  • You are only squaring and cubing the y .. for starters. Dividing through sum(input_int) makes no sense at all for your taks.

    – Patrick Artner
    Mar 9 at 9:41











  • Reads like a university/college/interview programming assignment...

    – dijksterhuis
    Mar 9 at 12:43
















Please add some context to your question as well as formatting your code.

– Tobias Wilfert
Mar 9 at 8:18





Please add some context to your question as well as formatting your code.

– Tobias Wilfert
Mar 9 at 8:18













You are only squaring and cubing the y .. for starters. Dividing through sum(input_int) makes no sense at all for your taks.

– Patrick Artner
Mar 9 at 9:41





You are only squaring and cubing the y .. for starters. Dividing through sum(input_int) makes no sense at all for your taks.

– Patrick Artner
Mar 9 at 9:41













Reads like a university/college/interview programming assignment...

– dijksterhuis
Mar 9 at 12:43





Reads like a university/college/interview programming assignment...

– dijksterhuis
Mar 9 at 12:43












2 Answers
2






active

oldest

votes


















0














Your code is very hard to understand and does not even run.



Based on your description of the goal, I can suggest a simpler code to achieve it:



def calc_ratio(n):
sum_3 = sum(x**3 for x in range(1, n+1))
sum_2 = sum(x**2 for x in range(1, n+1))
return sum_3 / sum_2


This would give these results:



>>> calc_ratio(10)
7.857142857142857
>>> calc_ratio(100)
75.3731343283582
>>> calc_ratio(1000)
750.3748125937032
>>> calc_ratio(10000)
7500.374981250938
>>> calc_ratio(100000)
75000.37499812501





share|improve this answer






























    0














    from functools import reduce
    import ast,sys
    input_int = int(sys.stdin.read())

    num_list = [x for x in range(1, input_int+1)]
    print(reduce(lambda x, y : x + y ** 3, num_list) / reduce(lambda x, y : x + y ** ,num_list))





    share|improve this answer




















    • 2





      Please consider adding a description of your code so we know what it does and why.

      – Pikachu the Purple Wizard
      Mar 9 at 19:33











    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55075341%2fcompute-the-ratio-of-the-sum-of-cube-of-the-first-n-natural-numbers-to-the-sum%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Your code is very hard to understand and does not even run.



    Based on your description of the goal, I can suggest a simpler code to achieve it:



    def calc_ratio(n):
    sum_3 = sum(x**3 for x in range(1, n+1))
    sum_2 = sum(x**2 for x in range(1, n+1))
    return sum_3 / sum_2


    This would give these results:



    >>> calc_ratio(10)
    7.857142857142857
    >>> calc_ratio(100)
    75.3731343283582
    >>> calc_ratio(1000)
    750.3748125937032
    >>> calc_ratio(10000)
    7500.374981250938
    >>> calc_ratio(100000)
    75000.37499812501





    share|improve this answer



























      0














      Your code is very hard to understand and does not even run.



      Based on your description of the goal, I can suggest a simpler code to achieve it:



      def calc_ratio(n):
      sum_3 = sum(x**3 for x in range(1, n+1))
      sum_2 = sum(x**2 for x in range(1, n+1))
      return sum_3 / sum_2


      This would give these results:



      >>> calc_ratio(10)
      7.857142857142857
      >>> calc_ratio(100)
      75.3731343283582
      >>> calc_ratio(1000)
      750.3748125937032
      >>> calc_ratio(10000)
      7500.374981250938
      >>> calc_ratio(100000)
      75000.37499812501





      share|improve this answer

























        0












        0








        0







        Your code is very hard to understand and does not even run.



        Based on your description of the goal, I can suggest a simpler code to achieve it:



        def calc_ratio(n):
        sum_3 = sum(x**3 for x in range(1, n+1))
        sum_2 = sum(x**2 for x in range(1, n+1))
        return sum_3 / sum_2


        This would give these results:



        >>> calc_ratio(10)
        7.857142857142857
        >>> calc_ratio(100)
        75.3731343283582
        >>> calc_ratio(1000)
        750.3748125937032
        >>> calc_ratio(10000)
        7500.374981250938
        >>> calc_ratio(100000)
        75000.37499812501





        share|improve this answer













        Your code is very hard to understand and does not even run.



        Based on your description of the goal, I can suggest a simpler code to achieve it:



        def calc_ratio(n):
        sum_3 = sum(x**3 for x in range(1, n+1))
        sum_2 = sum(x**2 for x in range(1, n+1))
        return sum_3 / sum_2


        This would give these results:



        >>> calc_ratio(10)
        7.857142857142857
        >>> calc_ratio(100)
        75.3731343283582
        >>> calc_ratio(1000)
        750.3748125937032
        >>> calc_ratio(10000)
        7500.374981250938
        >>> calc_ratio(100000)
        75000.37499812501






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 9 at 11:23









        RalfRalf

        7,55341438




        7,55341438























            0














            from functools import reduce
            import ast,sys
            input_int = int(sys.stdin.read())

            num_list = [x for x in range(1, input_int+1)]
            print(reduce(lambda x, y : x + y ** 3, num_list) / reduce(lambda x, y : x + y ** ,num_list))





            share|improve this answer




















            • 2





              Please consider adding a description of your code so we know what it does and why.

              – Pikachu the Purple Wizard
              Mar 9 at 19:33















            0














            from functools import reduce
            import ast,sys
            input_int = int(sys.stdin.read())

            num_list = [x for x in range(1, input_int+1)]
            print(reduce(lambda x, y : x + y ** 3, num_list) / reduce(lambda x, y : x + y ** ,num_list))





            share|improve this answer




















            • 2





              Please consider adding a description of your code so we know what it does and why.

              – Pikachu the Purple Wizard
              Mar 9 at 19:33













            0












            0








            0







            from functools import reduce
            import ast,sys
            input_int = int(sys.stdin.read())

            num_list = [x for x in range(1, input_int+1)]
            print(reduce(lambda x, y : x + y ** 3, num_list) / reduce(lambda x, y : x + y ** ,num_list))





            share|improve this answer















            from functools import reduce
            import ast,sys
            input_int = int(sys.stdin.read())

            num_list = [x for x in range(1, input_int+1)]
            print(reduce(lambda x, y : x + y ** 3, num_list) / reduce(lambda x, y : x + y ** ,num_list))






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 9 at 19:20









            Justice_Lords

            732211




            732211










            answered Mar 9 at 12:33









            Pradeep vPradeep v

            1




            1







            • 2





              Please consider adding a description of your code so we know what it does and why.

              – Pikachu the Purple Wizard
              Mar 9 at 19:33












            • 2





              Please consider adding a description of your code so we know what it does and why.

              – Pikachu the Purple Wizard
              Mar 9 at 19:33







            2




            2





            Please consider adding a description of your code so we know what it does and why.

            – Pikachu the Purple Wizard
            Mar 9 at 19:33





            Please consider adding a description of your code so we know what it does and why.

            – Pikachu the Purple Wizard
            Mar 9 at 19:33

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55075341%2fcompute-the-ratio-of-the-sum-of-cube-of-the-first-n-natural-numbers-to-the-sum%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved