text
stringlengths
0
312
# write a python program to make use of modulo operator
print(f'modulo 15 % 4: Sol->{15 % 4}')
# write a python program to explain enclosing and global scope
x = 'global'
def f():
x = 'enclosing'
def g():
print(x)
g()
return x
obj1 = f()
print('explain global scope:',obj1)
# write a python program to expain local and global scope
def f1():
x = 'enclosing'
def g():
x = 'local'
return x
x=g()
return x
obj2 = f1()
print('explain local scope:',obj2)
# write a python program to make use of regular expression for matching
import re
print('Find the characters in the given string:',re.findall(r'[a-z]+', '123FOO456', flags=re.IGNORECASE))
# write a python program to make use of regular expression for matching
s = 'foo123bar'
m = re.findall('123', s)
print('find the number position:',m)
# write a python program to convert lower string to UPPERCASE
a = 'string'
print(f'convert lowercase to uppercase:{a.upper()}')
# write a python program to convert uppercase string to lower
a = 'STRING'
print(f'convert lowercase to uppercase:{a.lower()}')
# write a Python Program to Find the Square Root
num = 8
num_sqrt = num ** 0.5
print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))
# write a Python Program to Convert Kilometers to Miles
kilometers = 10.0
conv_fac = 0.621371
miles = kilometers * conv_fac
print('%0.2f kilometers is equal to %0.2f miles' %(kilometers,miles))
# write a Python Program to Convert Celsius To Fahrenheit
celsius = 37.5
fahrenheit = (celsius * 1.8) + 32
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit))
# write a Python Program to Check if a Number is Positive, Negative or 0
num = 10
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")
# Python Program to Check if a Number is Odd or Even
num = 100
if (num % 2) == 0:
print("{0} is Even".format(num))
else:
print("{0} is Odd".format(num))
# Python Program to Display the multiplication Table
num = 12
for i in range(1, 11):
print(num, 'x', i, '=', num*i)
# write a program for Rolling the dices
import random
min = 1
max = 6
print("Rolling the dices...and the values are",random.randint(min, max))
print("Rolling the dices...and the values are",random.randint(min, max))
# write a python program to calculate the average
list1 = [1,3,4,5]
average = (sum(list1)) / len(list1)
print(f"the average score is: {average} ")