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 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 python program to check the length of list
sample_list = ['a','b','c']
print(f'length of sample_list is {len(sample_list)}')
write a Python program to calculate number of days between two dates.
from datetime import date
f_date = date(2019, 4, 15) # YYYY/MM/DD
l_date = date(2020, 4, 15) # YYYY/MM/DD
delta = l_date - f_date
print(f'No of days between {f_date} and {l_date} is:{delta.days}')
write a Python program to convert Python objects into JSON strings.
import json
python_dict = {"name": "David", "age": 6, "class":"I"}
json_dict = json.dumps(python_dict, sort_keys=True, indent=4)
print(f"json dict : {json_dict}")
write a Python program to get the largest number from a list
def max_num_in_list(list):
max = list[0]
for a in list:
max = a if a > max else max
return max
print(f'max_num_in_list [1, 10, -8, 0], Ans:{max_num_in_list([1, 10, -8, 0])}')