Function to print calendar
def show_mm_calendar(mm: int, yyyy: int):
import calendar
print(calendar.month(yyyy, mm)
21 Create a function that takes a list of numbers between 1 and 10 (excluding one number) and returns the missing number.
def print_miss_num(l: list):
print(f'Missing number is {55-sum(l)}')
Function to print marsh code equivalent from string.
def encode_marsh(sen : str):
char_to_dots = { 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.',
'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..',
'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.',
'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-',
'Y': '-.--', 'Z': '--..', ' ': ' ', '0': '-----',
'1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....',
'6': '-....', '7': '--...', '8': '---..', '9': '----.',
'&': '.-...', "'": '.----.', '@': '.--.-.', ')': '-.--.-', '(': '-.--.',
':': '---...', ',': '--..--', '=': '-...-', '!': '-.-.--', '.': '.-.-.-',
'-': '-....-', '+': '.-.-.', '"': '.-..-.', '?': '..--..', '/': '-..-.'
}
for i in sen:
print(char_to_dots[i.upper()])
Function to intern a sentence.
def check_intern(a , b):
if a is b:
print(f'{a} and {b} is interned by Python')
else:
print(f'{a} and {b} is not interned by Python')
24 convert string to intern string
def str_to_intern_str(a):
import sys
b = sys.intern(a)
if a is b:
print('Sentence is interned')
else:
raise ValueError('This should not happen')
def time_calc(n: int):
import time
start = time.perf_counter()
for i in range(10000000):
n*2
end = time.perf_counter()
return end-start