Scientific Notation using Python

Scientific Notation using Python


*Featured Code Submitted and Created by 

VENOM666


Python


# 365 DAYS OF CODE: DAY 2: SCIENTIFIC NOTATION (ASSIGNMENT)
# https://www.sololearn.com/learn/10004/?ref=app
# by: VENOM666

from math import floor

def scientific_notation(num):
    
    if num > 1: # accepts only arguments that is not a float less than 1, e.g 0.00082
        exponent = 0
    
        while floor(num) > 10: #leaves one digit at the ones place
            num = num / 10 #shift decimal place to the right
            exponent += 1

        print(('{} x 10^{}').format(num, exponent))

        
    else:
        exponent = 0
        
        while floor(num) == 0: #ones place must have value greater than 0
            num = num * 10 #shift decimal place to the left
            exponent += 1
            
        print(('{} x 10^-{}').format(round(num, 4), exponent))
        
scientific_notation(12351283517280561)
scientific_notation(0.000000065)


Click here to run this Code



 





Comments

Popular posts from this blog

Crypto Mining

Multi-tap Keypad Text Entry