x = input('Enter first integer:') x = float(x) #this converts a string into a floating number x = int(x) #this truncates a floating number into an integer y = input('Enter second integer:') y = float(y) #this converts a string into a floating number y = int(y) #this truncates a floating number into an integer print('The sum of',x,'and',y,'is',x,'+',y,'=',x+y) print(x,'minus',y,'gives',x,'-',y,'=',x-y) print('The product of',x,'and',y,'is',x,'*',y,'=',x*y) print('The quotient when',x,'is divided by',y,'is',x,'/',y,'=',x/y) print('The remainder when',x,'is divided by',y,'is',x,'%',y,'=',x%y) print('The floor function when',x,'is divided by',y,'is',x,'//',y,'=',x//y) print('The value when',x,'is raised to the power of',y,'is',x,'**',y,'=',x**y) print(x,'>',y,'is',x>y) #true if x>y print(x,'<',y,'is',x=',y,'is',x>=y) #true if x>=y print(x,'<=',y,'is',x<=y) #true if x<=y print(x,'==',y,'is',x==y) #true if x==y print(x,'!=',y,'is',x!=y) #true if x!=y print() import math print('math.pi =',math.pi) print('math.e =',math.e) print('math.tau =',math.tau) #a constant equal to 2π print('math.floor(1.5) =',math.floor(1.5)) #gives the largest integer less than or equal to a number print('math.ceil(1.5) =',math.ceil(1.5)) #gives the smallest integer greater than or equal to a number print('math.fabs(-1.5) =',math.fabs(-1.5)) #gives the absolute value of a number print('math.trunc(-1.1) =',math.trunc(-1.1)) #truncates a decimal into an integer print('math.modf(1.5) =',math.modf(1.5)) #gives the fractional and integer parts of a number print('math.sqrt(25) =',math.sqrt(25)) print('math.factorial(5) =',math.factorial(5)) print('math.exp(1) =',math.exp(1)) print('math.log(2) =',math.log(2)) #gives the logarithm to base e print('math.log2(2) =',math.log2(2)) #gives the logarithm to base 2 print('math.log10(1000) =',math.log10(1000)) #gives the logarithm to base 10 print('math.log(1000,10) =',math.log(1000,10)) #log(x,n) gives the logarithm to any base n print('math.pow(2,5) =',math.pow(2,5)) #pow(x,y) gives x raised to the power y print('math.fmod(-26,3) =',math.fmod(-26,3)) #fmod(x,y) gives x modulo y, it follows the sign of x print('math.remainder(-26,3) =',math.remainder(-26,3)) #remainder gives the difference from the quotient to the nearest integer print('math.gcd(12,18) =',math.gcd(12,18)) #gives the greatest common divisor print('math.modf(1.5) =',math.modf(1.5)) #gives the fractional and integer parts of a number print('math.degrees(math.pi) =',math.degrees(math.pi)) #converts an angle to degrees print('math.radians(180) =',math.radians(180)) #converts an angle to radians print('math.sin(math.pi) =',math.sin(math.pi)) #gives the sine print('math.cos(math.pi) =',math.cos(math.pi)) #gives the cosine print('math.tan(math.pi) =',math.tan(math.pi)) #gives the tangent print('math.asin(1) =',math.asin(1)) #gives the inverse sine print('math.acos(1) =',math.acos(1)) #gives the inverse cosine print('math.atan(1) =',math.atan(1)) #gives the inverse tangent print('math.atan2(1,-1) =',math.atan2(1,-1)) #atan2(y, x) gives the angle atan(y/x) in the correct quadrant print('math.hypot(1,1) =',math.hypot(1,1)) #gives sqrt(x^2 + y^2) print('math.sinh(1) =',math.sinh(1)) #gives the hyperbolic sine print('math.cosh(1) =',math.cosh(1)) #gives the hyperbolic cosine print('math.tanh(1) =',math.tanh(1)) #gives the hyperbolic tangent print('math.asinh(1) =',math.asinh(1)) #gives the inverse hyperbolic sine print('math.acosh(1) =',math.acosh(1)) #gives the inverse hyperbolic cosine print('math.atanh(0) =',math.atanh(0)) #gives the inverse hyperbolic tangent print() from fractions import Fraction as F print('F(1,3) =',F(1,3)) print('F(1.5) =',F(1.5)) print('F(1,2) + F(1,3) =',F(1,2) + F(1,3)) from decimal import Decimal as D print("D('1.1') + D('2.2') =",D('1.1') + D('2.2')) print('Formatting to 5 decimal places =',"{:.5f}".format(math.pi)) #to 5 decimal places print('Formatting with comma separators =',"{:,}".format(1000000)) #with comma separators print() import random print('A random number in the range [0.0, 1.0) =',random.random()) #a random number in the range [0.0, 1.0) print('A random list of integers from 1 to 10 is') for i in range(10): print(random.randint(1,10),end=' ') #gives a random integer in the given range print('\nA random list of integers from the range (2,10,2) is') for i in range(10): print(random.randrange(2,10,2),end=' ') #gives a random number in the range(start, stop, step) print() x = ['a','b','c','d','e'] random.shuffle(x) #randomly shuffles a list print('Shuffling a list gives',x) print('A random sample without replacement from a population [1,2,3,4,5,6,7,8,9,10] =',random.sample([1,2,3,4,5,6,7,8,9,10], 5)) #gives a random sample without replacement from the population sequence of a given length print() import cmath z=1+1j print('z =',z) print('z.real =',z.real) #gives the real part of a complex number print('z.imag =',z.imag) #gives the imaginary part of a complex number print('cmath.phase(z) =',cmath.phase(z)) #gives the argument of a complex number print('cmath.polar(z) =',cmath.polar(z)) #gives the modulus and argument of a complex number print('cmath.rect(math.sqrt(2),math.pi/4) =',cmath.rect(math.sqrt(2),math.pi/4))#gives the cartesian form of a complex number