logo

Wiskundige functies in Python | Set 1 (numerieke functies)

In Python kunnen een aantal wiskundige bewerkingen gemakkelijk worden uitgevoerd door een module met de naam 'wiskunde' te importeren die verschillende functies definieert die onze taken eenvoudiger maken. 1. plafond() : - Deze functie retourneert de kleinste integrale waarde groter dan het getal . Als getal al een geheel getal is, wordt hetzelfde getal geretourneerd. 2. verdieping() : - Deze functie retourneert de grootste integrale waarde kleiner dan het getal . Als getal al een geheel getal is, wordt hetzelfde getal geretourneerd. 

Python
# Python code to demonstrate the working of  # ceil() and floor()  # importing 'math' for mathematical operations  import math a = 2.3 # returning the ceil of 2.3  print ('The ceil of 2.3 is : ' end='') print (math.ceil(a)) # returning the floor of 2.3  print ('The floor of 2.3 is : ' end='') print (math.floor(a)) 

Uitgang:



The ceil of 2.3 is : 3 The floor of 2.3 is : 2

Tijdcomplexiteit: O(1)

Hulpruimte: O(1)


3. Fabs() : - Deze functie retourneert de absolute waarde van het nummer. 4. faculteit() : - Deze functie retourneert de faculteit van het nummer. Er wordt een foutmelding weergegeven als het getal niet integraal is. 



Python
# Python code to demonstrate the working of  # fabs() and factorial()  # importing 'math' for mathematical operations  import math a = -10 b= 5 # returning the absolute value.  print ('The absolute value of -10 is : ' end='') print (math.fabs(a)) # returning the factorial of 5  print ('The factorial of 5 is : ' end='') print (math.factorial(b)) 

Uitgang:

The absolute value of -10 is : 10.0 The factorial of 5 is : 120

Tijdcomplexiteit: O(b)

Hulpruimte: O(1)




5. kopieerteken(a b) :- Deze functie retourneert het getal met de waarde van 'a' maar met het teken 'b' . De geretourneerde waarde is van het float-type. 6. ggd() : - Deze functie wordt gebruikt om de grootste gemene deler van 2 getallen genoemd in zijn argumenten. Deze functie werkt in Python 3.5 en hoger. 

Python
# Python code to demonstrate the working of  # copysign() and gcd()  # importing 'math' for mathematical operations  import math a = -10 b = 5.5 c = 15 d = 5 # returning the copysigned value.  print ('The copysigned value of -10 and 5.5 is : ' end='') print (math.copysign(5.5 -10)) # returning the gcd of 15 and 5  print ('The gcd of 5 and 15 is : ' end='') print (math.gcd(515)) 

Uitgang:

The copysigned value of -10 and 5.5 is : -5.5 The gcd of 5 and 15 is : 5

Tijdcomplexiteit: O(min(cd))

Hulpruimte: O(1)


mockito wanneer dan ook