In Python können eine Reihe mathematischer Operationen problemlos ausgeführt werden, indem ein Modul namens „math“ importiert wird, das verschiedene Funktionen definiert, was unsere Aufgaben erleichtert. 1. Decke() :- Diese Funktion gibt die zurück kleinster ganzzahliger Wert größer als die Zahl . Wenn die Zahl bereits eine Ganzzahl ist, wird dieselbe Zahl zurückgegeben. 2. Etage() :- Diese Funktion gibt die zurück größter Integralwert kleiner als die Zahl . Wenn die Zahl bereits eine Ganzzahl ist, wird dieselbe Zahl zurückgegeben.
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))
Ausgabe:
The ceil of 2.3 is : 3 The floor of 2.3 is : 2
Zeitkomplexität: O(1)
Hilfsraum: O(1)
3. Fabs() :- Diese Funktion gibt die zurück absoluter Wert der Zahl. 4. Fakultät() :- Diese Funktion gibt die zurück Fakultät der Zahl. Wenn die Zahl nicht ganzzahlig ist, wird eine Fehlermeldung angezeigt.
# 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))
Ausgabe:
The absolute value of -10 is : 10.0 The factorial of 5 is : 120
Zeitkomplexität: O(b)
Hilfsraum: O(1)
5. Copysign(a b) :- Diese Funktion gibt die Nummer mit zurück Wert von 'a', aber mit dem Vorzeichen von 'b' . Der zurückgegebene Wert ist vom Typ Float. 6. gcd() :- Diese Funktion wird verwendet, um die zu berechnen größter gemeinsamer Teiler von 2 Zahlen in seinen Argumenten erwähnt. Diese Funktion funktioniert in Python 3.5 und höher.
# 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))
Ausgabe:
The copysigned value of -10 and 5.5 is : -5.5 The gcd of 5 and 15 is : 5
Zeitkomplexität: O(min(cd))
Hilfsraum: O(1)
Array-Liste sortieren