DEV Community

Durga Pokharel
Durga Pokharel

Posted on

1

Day 5 of 100DaysOfCode: Python Code to Find Perfect Cube in Range

This is the 5th day of 100DaysOfCode and I am learning more from Coursera's Python Data Structure Course and did some assignments also.
But for my own exercise, I tried to write a code to find perfect cube numbers in a given range.
My solution is like below:

  • Create a list of numbers in a given range.
  • Loop through each number and find its cube root value.
  • Round the number came after making cube root of a number and find its cube.
  • If current number is equal to the number came after cubing the root value then the current number is perfect cube number and append it to our list.
numbers = list(range(1,202))
cube_root_numbers = []
for n in numbers:
    cube_root = (n)**(1/3)
    int_cube_root = round(cube_root)
    if int_cube_root**3 == n:
        cube_root_numbers.append(n)
        print(n)
Enter fullscreen mode Exit fullscreen mode

Day 5 of #100DaysOfCode and #Python
* More about file handling
* More about List and Tuples
* Python code to find the perfect cube number in given range. pic.twitter.com/fTNQm4r5n4

β€” Durga Pokharel (@mathdurga) December 28, 2020

Image of Docusign

πŸ› οΈ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay