Numeric Functions
Numeric Functions
abs ( ) : Returns an absolute value of a number. The argument may be an integer or a floating point number.
Synatx:
abs (x)
Example:
x=20
y=-23.2
print('x = ', abs(x))
print('y = ', abs(y))
Output:
x = 20
y = 23.2
ord ( ) : Returns the ASCII value for the given Unicode character. This function is inverse of chr() function.
Sytanx:
ord (c)
Example:
c= 'a'
d= 'A'
print ('c = ',ord (c))
print ('A = ',ord (d))
Output:
c = 97
A = 65
chr ( ) : Returns the Unicode character for the given ASCII value. This function is inverse of ord() function.
Syntax:
chr (i)
Example:
c=65
d=43
print (chr (c))
prin t(chr (d))
Output:
A
+
bin ( ) : Returns a binary string prefixed with “0b” for the given integer number.
Note: format () can also be used instead of this function.
Syntax:
bin (i)
Example:
x=15
y=101
print ('15 in binary : ',bin (x))
print ('101 in binary : ',bin (y))
Output:
15 in binary : 0b1111
101 in binary : 0b1100101
min ( ) : Returns the minimum value in a list.
Syntax:
min (list)
Example:
MyList = [21,76,98,23]
print ('Minimum of MyList :', min(MyList))
Output:
Minimum of MyList : 21
Qus. 1 : The function pow(x,y,z) is evaluated as:
- (x**y)**z
- (x**y) / z
- (x**y) % z
- (x**y)*z
- Error
- -5
- 5
- 5.0
- Error, 6
- 12, Error
- 12, 6
- Error, Error
Programs
Python program to convert decimal into other number systems
python program that generates six random numbers in a sequence created with start stop step
Python program to illustrate the global variable
python program to create a function to calculate factorial value
Python program to find the sum of factorial upto n terms using function
python program to create a function for reverse the number
Python program to check number is Palindrome or not using function
Python program to create a function for calculating sum of digit
Python program to create recursive function to find factorial
python function to accept 2 number and return addition subtraction multiplication and division
python function to accept number of days and return week and days to its equivalent
python function to extract the day month year from given date
Python function to find the sum of all numbers between 100 and 500 which are divisible by 2
Python function to get two matrices and multiply them
python recursive function to find the sum of digits
python recursive function to print the reverse of number
Write a function with name dividebyfive which generate and prints a random integer number from the range 0 to 100 and then return True if the randomly generated number is divisible by 5, and False otherwise.