Monday, June 17, 2019

Python Random Function

Python Random Function





#Python | random.sample() function

import random

print ("The random value from random.seed(10) is : ", end="")
print (random.seed(10))
#If we wanted a random integer, we can use the randint function
#Randint accepts two parameters: a lowest and a highest number.
#Generate integers between 1,5. The first value should be less than the second.
print ("The random integer value from 10 to 100 is : ", end="")
print (random.randint(10,100))

#If you want a larger number, you can multiply it.
#For example, a random number between 0 and 100:
print ("The random value of random function is : ", end="")
print (random.random()*20)

# Python code to demonstrate the working of
# randrange()
print ("The random range of 1000 is : ", end="")
print (random.randrange(1000))

print ("The random range of 10 to 100 by skipping 2 is : ", end="")
print (random.randrange(10,100,2))

a=[1,2,9,'c','e',1.1]
print ("list a value is ",a)
print ("The list a value after random.shuffle function is : ", end="")
random.shuffle(a)
print (a)


Python math() function



Python math() function




#Python | math() function

import math

# Python code to demonstrate the working of

#demonstrate of math module to pi value
print ("The pi value is : ", end="")
print (math.pi)

#demonstrate of math module to math e value
print ("The math e value is : ", end="")
print (math.e)

#demonstrate of math module sin formula
print ("The sin(10) value is : ", end="")
print (math.sin(10))

#demonstrate of math module cos formula
print ("The cos(10) value is : ", end="")
print (math.cos(10))

#demonstrate of math module log10 formula
print ("The log10(10) value is : ", end="")
print (math.log10(10))

#demonstrate of math module for factorial function
print ("The factorial value of 5 is : ", end="")
print (math.factorial(5))

#demonstrate of math module for square root function
print ("The square root value of 9 is : ", end="")
print (math.sqrt(9))

# Python code to demonstrate the working of
# ceil() and floor()

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))


# Python code to demonstrate the working of
# fabs() and factorial()

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))


Monday, June 10, 2019

Assignment operators in Python

Assignment operators in Python



# Assignment operators in Python
# Operator Example Equivalent to
# = x = 5 x = 5
# += x += 5 x = x + 5
# -= x -= 5 x = x - 5
# *= x *= 5 x = x * 5
# /= x /= 5 x = x / 5
# %= x %= 5 x = x % 5
# //= x //= 5 x = x // 5
# **= x **= 5 x = x ** 5
# &= x &= 5 x = x & 5
# |= x |= 5 x = x | 5
# ^= x ^= 5 x = x ^ 5
# >>= x >>= 5 x = x >> 5
# <<= x <<= 5 x = x << 5

a = 10
b = 20
c = 0

print ("a value is ",a)
print ("b value is ",b)
print ("c value is ",c)

c = a + b
print (" Value of c is (c=a+b) ", c)

c += a
print (" Value of c is (c +=a)", c)

c *= a
print (" Value of c is (c *=a)", c)

c /= a
print (" Value of c is (c /=a)", c)

c  = 2
c %= a
print (" Value of c is (c %=a)", c)

c **= a
print (" Value of c is (c **= a)    ", c)

c //= a
print (" Value of c is (c //=a)", c)


Top ChatGPT Prompts for DevOps Engineers

  As a DevOps engineer, your role involves juggling complex tasks such as automation, infrastructure management, CI/CD pipelines, and troubl...