Python Forum
I'm having a problem with this cube root code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I'm having a problem with this cube root code
#1
I made this cube root code,but it didn't work for negative numbers. It always print "No cube roots" even though types of negative numbers are either float or int.
Here's my code:
a = input()
if type(a) == float or type(a) == int:
    if a > 0 or a == 0:
        print (round(float(a**(1/3)),15))
    else:
        a = abs(a)
        b = round(float(a**(1/3)),15)
        print (b * -1)
else:
    print ("No cube roots")
Reply


Messages In This Thread
I'm having a problem with this cube root code - by Duc311003 - May-16-2018, 05:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  keyboard module; must be root problem philipbergwerf 2 19,619 Apr-04-2021, 11:40 AM
Last Post: philipbergwerf
  unable to pass a input after changing the user from root to non root using python avinash 3 3,277 Apr-08-2019, 10:05 AM
Last Post: avinash
  Square and Cube roots. jarrod0987 2 5,607 Apr-13-2018, 09:30 PM
Last Post: casevh
  "³" math cube symbol encoding Ragnar 5 9,955 Mar-09-2018, 04:23 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020