text
stringlengths
0
312
# Write a program to extract and print digits of a number in reverse order. The number is input from user.
num = int(input("Enter a number with multiple digit: "))
n=0
while num>0:
a = num%10
num = num - a
num = num/10
print(int(a),end="")
n = n + 1
# Write a function that takes in height(m) and weight(kg), calculates BMI and prints the comments
def bmi(height: "Meters", weight: "Kgs"):
bmi = weight/(height**2)
print("Your BMI is: {0} and you are ".format(bmi), end='')
if ( bmi < 16):
print("severely underweight.")
elif ( bmi >= 16 and bmi < 18.5):
print("underweight.")
elif ( bmi >= 18.5 and bmi < 25):
print("healthy.")
elif ( bmi >= 25 and bmi < 30):
print("overweight.")
elif ( bmi >=30):
print("severely overweight.")
# Write a program that prints all the alphabets in a string and skips all other characters
string = "$john.snow#@Got.bad_ending/com"
for ch in string:
if (ch>='A' and ch<='Z') or (ch>='a' and ch<='z'):
print(ch, end='')
else:
pass
# Write a function that takes number of disks in tower of hanaoi problem and returns the minimum number of steps required
def hanoi(x):
if x == 1:
return 1
else:
return 2*hanoi(x-1) + 1
# Write a lambda function to convert centimeters to inches
cm_to_inch = lambda x: x/2.54
# Write a lambda function to find the union of two lists
union = lambda a, b: list(set(a)|set(b))
# Write a lambda function to find the intersection of two lists
intersection = lambda a, b: list(set(a)&set(b))
# Write a program that adds the square of two numbers and prints it
a = 32
b = 21
result = a**2 + b**2
print(result)
# Write a python function to concat the input strings and there's also a choice for seperator
def con_str(*args, sep = ' '):
return sep.join(args)
# Write a program to print all the even numbers in a range
r1, r2 = 1, 28
for _ in range(r1, r2+1):
if _%2 == 0:
print(_)
# write a python program to sort dictionary items
dict1 = {'car': [7, 6, 3],
'bike': [2, 10, 3],
'truck': [19, 4]}
print(f"The original dictionary is : {str(dict1)}")
res = dict()
for key in sorted(dict1):
res[key] = sorted(dict1[key])
print(f"The sorted dictionary : {str(res)}")
# write a program to display date and time
import datetime
now = datetime.datetime.now()
time= now.strftime("%Y-%m-%d %H:%M:%S")
print(f"Current date and time : {time}")
# write a program to return the absolute value
num = -10