Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Python: Return the arctangent of x in radians

import math
print math.atan(-1./-1.)
print math.atan2(-1., -1.)

Python: create a function that accepts any number of positional arguments

# return th sum of arguments
def sum_args(*numbers):
    return sum(numbers)
print sum_args(15, -42, 48, 85, 20)

Python: Return the cosine of a value

import math
print math.cos(1024)

Python: Print rounds

num = 6 / 7.0
print num
print round(num)

Python: get maximum value of a list

print max(2, 3, 78, -100, 24)

Python: How to use Math.pi and Math.e

import math
print math.pi
print math.e

Python: get min value of a list

print min(2, 3, 78, -100, 24)

Python: Get absolute value

import math
print abs(-16)   # absolute value 
print pow(2, 4)  # raise a number to a power

Python: return the square root of a number

from math import sqrt
for x in range(99, 0, -1):
    root = sqrt(x)
    if root == int(root):
        print x