Python File 905
Python File 905
Task - 1
Write a program to demonstrate different number data types in Python.
a = 31;
b = "hi";
c = 3 + 9j;
d = [1,2,3];
e = (1,2,3);
f = {1:"soen",2:"unknown",3:"b"};
g = True;
variables = [a, b, c, d, e, f, g];
varName = ["a","b","c","d","e","f","g"];
for i in range(7):
typ = str(type(variables[i]));
print("Type of ",varName[i],"is",typ[8:-2],"where",varName[i],"=",variables[i]);
BTCS 513-18 2232905
Task - 2
Write a program to perform different Arithmetic Operations on numbers in Python.
while True:
print("------------------CALCULATOR------------------\n\nChoose an option")
print("1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n5. Floor Division\n6.
Raise to Power\n7. Modulo\n8. Exit")
n1 = int(input("enter first number >>> "))
n2 = int(input("enter second number >>> "))
choice = int(input("Enter your choice >>> "))
match choice:
case 1:
print(n1, "+", n2, "=", n1 + n2)
case 2:
print(n1, "-", n2, "=", n1 - n2)
case 3:
print(n1, "*", n2, "=", n1 * n2)
case 4:
print(n1, "/", n2, "=", n1 / n2)
case 5:
print(n1, "//", n2, "=", n1 // n2)
case 6:
print(n1, "**", n2, "=", n1 ** n2)
case 7:
print(n1, "%", n2, "=", n1 % n2)
case 8:
break
case default:
print("INVALID CHOICE !")
BTCS 513-18 2232905
Task – 3
Write a program to create, concatenate and print a string and accessing sub-string
from a given string.
created = False
loop = True
while loop:
print("Choose an option\n1. Create a string\n2. Concatenate a string\n3. Print the string\
n4. Find a substring\n5. Exit")
choice = int(input("Enter your choice >> "))
match choice:
case 1:
if created == True:
print("string already created\nDo you want to update it?")
choice_c1 = input("y/n >>> ")
if choice_c1 == 'y':
s = input("Enter your string >> ")
print("String created is >>> ",s)
elif choice_c1 == 'n':
pass
else:
print("INVALID CHOICE !")
if created == False:
s = input("Enter your string >> ")
print("String created is >>> ",s)
created = True
case 2:
s_con1 = input("Enter a first string to concatenate >>> ")
s_con2 = input("Enter a second string to concatenate >>> ")
s_final = s_con1 + s_con2
print("Concatenated string is >>> ",s_final)
case 3:
print("String printed >>> ",input("Enter a string to be printed >>> "))
case 4:
main_str = input("Enter a string >>> ")
sub_str = input("Enter a substring to be found in main string >>> ")
if sub_str in main_str:
print("substring '",sub_str,"' is present in main string '",main_str,"'")
else:
print("Substring not Found !")
case 5:
loop = False
BTCS 513-18 2232905
BTCS 513-18 2232905
Task – 4
Write a python script to print the current date in the following format “Sun May 29
02:26:23 IST 2017”.
import datetime
import pytz
timeZone = pytz.timezone('Asia/Kolkata')
now = datetime.datetime.now(timeZone)
date = now.strftime("%a %b %d %H:%M:%S %Z %z %Y")
print(date)
BTCS 513-18 2232905
Task – 5
Write a program to create, append, and remove lists in python.
created = False
loop = True
while loop:
print("Choose an option\n1. Created a list\n2. Append in list\n3. Insert at any location\n4.
Count number of elements\n5. Remove an element\n6. Exit")
choice = int(input("enter your choice >>> "))
try:
match choice:
case 1:
if created == True:
print("list already created")
if created == False:
l = []
created = True
print("empty list created >>> ",l)
case 2:
l.append(int(input("enter a number >>> ")))
print("element appended >>> ",l)
case 3:
l.insert(int(input("Enter index number >>> ")),int(input("enter a number >>> ")))
print("element inserted >>> ",l)
case 4:
print("Number of elements in list are >>> ",len(l))
case 5:
print("Choose an option\n1. Remove by index number\n2. Remove by value")
sub_choice = int(input("enter your choice >>> "))
match sub_choice:
case 1:
l.pop(int(input("enter index number >>>")))
print("element removed >>> ",l)
case 2:
l.remove(int(input("enter the value >>> ")))
print("element removed >>> ",l)
case 6:
loop = False
case default:
print("Invalid Input !")
except NameError:
print("List not created yet !")
except IndexError:
print("Nothing found at given index !")
BTCS 513-18 2232905
except ValueError:
print("Given value not found !")
BTCS 513-18 2232905
Task – 6
Write a program to demonstrate working with tuples in python.
created = False
loop = True
while loop:
print("Choose an option\n1. Created a Tuple\n2. Append in Tuple\n3. Insert at any
location\n4. Count number of elements\n5. Remove an element\n6. Exit")
choice = int(input("enter your choice >>> "))
try:
match choice:
case 1:
if created == True:
print("tuple already created")
if created == False:
l = ()
created = True
print("empty tuple created >>> ",l)
case 2:
l = list(l)
l.append(int(input("enter a number >>> ")))
l = tuple(l)
print("element appended >>> ",l)
case 3:
l = list(l)
l.insert(int(input("Enter index number >>> ")),int(input("enter a number >>> ")))
l = tuple(l)
print("element inserted >>> ",l)
case 4:
print("Number of elements in tuple are >>> ",len(l))
case 5:
l = list(l)
print("Choose an option\n1. Remove by index number\n2. Remove by value")
sub_choice = int(input("enter your choice >>> "))
match sub_choice:
case 1:
l.pop(int(input("enter index number >>>")))
l = tuple(l)
print("element removed >>> ",l)
case 2:
l.remove(int(input("enter the value >>> ")))
l = tuple(l)
print("element removed >>> ",l)
case 6:
BTCS 513-18 2232905
loop = False
case default:
print("Invalid Input !")
except NameError:
print("tuple not created yet !")
except IndexError:
print("Nothing found at given index !")
except ValueError:
print("Given value not found !")
BTCS 513-18 2232905
Task – 7
Write a program to demonstrate working with dictionaries in python.
created = False
loop = True
while loop:
print("Choose an option\n1. Created a dictionary\n2. Insert in dictionary\n3. Update at any
key value\n4. Count number of elements\n5. Remove an element\n6. Print dictionary\n7.
Exit")
choice = int(input("enter your choice >>> "))
try:
match choice:
case 1:
if created == True:
print("dictionary already created")
if created == False:
d = {}
created = True
print("empty dictionary created >>> ",d)
case 2:
d[int(input("Enter a int for key value >>> "))] = input("Enter a string value >>> ")
print("element inserted >>> ",d)
case 3:
d.update({int(input("Enter a int for key value >>> ")): input("Enter a string value
to be updated >>> ")})
print("element updated >>> ",d)
case 4:
print("Number of key-value pairs in dictionary are >>> ",len(d))
case 5:
print("Choose an option\n1. Remove by key\n2. clear dictionary")
sub_choice = int(input("enter your choice >>> "))
match sub_choice:
case 1:
del d[int(input("Enter a int for key value to be removed >>> "))]
print("element removed >>> ",d)
case 2:
d.clear()
print("dictionary cleared",d)
case 6:
print(d)
case 7:
loop = False
case default:
print("Invalid Input !")
BTCS 513-18 2232905
except NameError:
print("dictionary not created yet !")
except IndexError:
print("Nothing found at given index !")
except ValueError:
print("Given value not found !")
BTCS 513-18 2232905
Task - 8
Write a python program to find largest of three numbers.
while(True):
first_number = int(input("Enter First Number >> "));
second_number = int(input("Enter Second Number >> "));
third_number = int(input("Enter Third Number >> "));
if first_number > second_number and first_number > third_number:
print("First entered number that is ",first_number," is greatest");
elif second_number > third_number and second_number > first_number:
print("Second entered number that is ",second_number," is greatest");
else:
print("Third entered number that is ",third_number," is greatest");
print("----------------------------------------------------------------");
BTCS 513-18 2232905
Task – 9
Write a Python program to convert temperatures to and from Celsius, Fahrenheit.
[ Formula: c/5 = f-32/9]
Task – 12
BTCS 513-18 2232905
Write a python program to find factorial of a number using Recursion.
def fact(n):
if n == 0:
return 1
else:
return n * fact(n-1)
print(fact(int(input("Enter a number: "))))
Task - 13
BTCS 513-18 2232905
Write a program that accepts the lengths of three sides of a triangle as inputs. The
program output should indicate whether or not the triangle is a right triangle (Recall
from the Pythagorean Theorem that in a right triangle, the square of one side equals
the sum of the squares of the other two sides).
def greatestSide(a,b,c):
if a > b and a > c:
return a;
elif b > c and b > a:
return b;
else:
return c;
def false():
print("Not a right angled triangle");
side1 = int(input("Enter the first side >> ")); s1 = side1**2;
side2 = int(input("Enter the second side >> ")); s2 = side2**2;
side3 = int(input("Enter the third side >> ")); s3 = side3**2;
hypo = greatestSide(side1,side2,side3);
if hypo == side1:
if s1 == s2+s3: print("Right angled triangle");
else: false();
elif hypo == side2:
if s2==s1+s3: print("Right angled triangle");
else: false();
elif hypo == side3:
if s3==s2+s1: print("Right angled triangle");
else: false();
Task – 14
BTCS 513-18 2232905
Write a python program to define a module to find Fibonacci Numbers and import the
module to another program.
mod.py
def fib(upto):
if upto <= 1:
return upto
return fib(upto - 1) + fib(upto - 2)
main.py
from mod import fib
upto = int(input("print series upto >>> "))
for i in range(upto):
print(fib(i))
Task - 15
BTCS 513-18 2232905
Write a python program to define a module and import a specific function in that
module to another program.
mod.py
def add(n1,n2):
return n1+n2
main.py
import mod
print(mod.add(int(input("enter first number >>> ")),int(input("enter first number >>> "))))
OR
Task – 16
BTCS 513-18 2232905
Write a script named copyfile.py. This script should prompt the user for the names of
two text files. The contents of the first file should be input and written to the second file.
file1 = open(input("enter file name to read from >>> "),"r")
file2 = open(input("enter file name to write to >>> "),"w+")
content = file1.read()
file2.write(content)
file2.seek(0)
print("content copied !")
copy.txt
Hello I am soen singh, how are u? I absolutely hate python...
a.txt
Hello I am soen singh, how are u? I absolutely hate python...
Task – 17
Write a program that inputs a text file. The program should print all of the unique
words in the file in alphabetical order.
copy.txt
Hello I am soen singh , how are u ? I absolutely hate python python is useless u know ? ?
Hello are u there absolutely soen singh useless u , ,
main.py
file = open(input("enter name of the file >>> "),"r")
content = file.read().split()
print(list(set(content)))
Task – 18
BTCS 513-18 2232905
Write a Python class to convert an integer to a roman numeral.
class converter:
def to_roman(num):
val = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
syb = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]
roman_num = ''
for v, s in zip(val, syb):
roman_num += s * (num // v)
num %= v
return roman_num
print(converter.to_roman(int(input("Enter an integer"))))
Task – 19
BTCS 513-18 2232905
Write a Python class to implement pow(x, n).
class power:
def pow(x,n):
if n == 0:
return 1
elif n < 0:
return 1 / pow(x, -n)
else:
return x * pow(x, n-1)
print(power.pow(int(input("enter the base value >>> ")),int(input("enter the power >>> "))))
Task – 20
Write a Python class to reverse a string word by word.
class rev:
def reverse(s):
words = s.split()
return ' '.join(words[::-1])
print(rev.reverse(input("enter a string >>> ")))
Task – 21 A
BTCS 513-18 2232905
Write a python program to construct the following pattern, using a for loop and range
function.
Task – 21 B
Write a python program to construct the following pattern, using a for loop and range
function.
Task – 21 C
BTCS 513-18 2232905
Write a program to print table of a number.
Task - 22
BTCS 513-18 2232905
Write a python program to check whether a given number is even or odd.
Task - 23
Write a python program to find the sum of all the digits of a given number.
Task - 24
BTCS 513-18 2232905
Write a python program to check whether a number is palindrome or not.
Task - 25
Write a python program to check whether a number is palindrome or not.
Task - 26
BTCS 513-18 2232905
Write a python program to find even length words in a string.
Task - 27
Write a python program to swap all dots and commas in string.
Task - 28
Write a python program to change “F.R.I.E.N.D.S” to “friends”.
BTCS 513-18 2232905
a="F.R.I.E.N.D.S"
b=a.replace('.','')
print(b.lower())
Task - 29
Write a python program to extract digits from a given string.
Task – 30
Program for insertion in a list before any element.
BTCS 513-18 2232905
def insert_before(lst, new_element, before_element):
idx = lst.index(before_element)
lst.insert(idx, new_element)
return lst
List = []
for i in range(5):
List.append(int(input("enter a no >>> ")))
new_element = int(input("enter element to insert >>> "))
before_element = int(input("enter element before >>> "))
print(insert_before(List, new_element, before_element))
Task – 31
Write a Program to remove all duplicates from a list.
def duplicates(lst):
BTCS 513-18 2232905
seen = set()
result = []
for elem in lst:
if elem not in seen:
result.append(elem)
seen.add(elem)
return result
my_list = []
for i in range(int(input("enter no of elements of the list >>> "))):
my_list.append(int(input("enter a int >>> ")))
print(duplicates(my_list))
Task – 32
WAP that creates a list ‘L’ of 10 random integers. Then create ODD and EVEN lists
containing odd and even values respectively from ‘L’.
BTCS 513-18 2232905
import random
a = []
for b in range(10):
c = random.randint(1, 100)
a.append(c)
d = []
e = []
for f in range(len(a)):
if a[f] % 2 == 0:
e.append(a[f])
else:
d.append(a[f])
print("Original List:", a)
print("Odd List:", d)
print("Even List:", e)
Task – 33
Write a program to delete all consonants from string "hello cse python" and
create a new string
BTCS 513-18 2232905
s = "hello cse python"
t = ""
v = "aeiouAEIOU"
for c in s:
if c in v or c == " ":
t += c
print("New String:", t)
Task – 34
Write a program that takes your full name as input and displays the abbreviations
of the first and middle names except the last name which is displayed as it is. For
example, if your name is Robin Ramesh Kumar, then the output should be
R.R.Kumar.
n = input("Enter your full name: ")
p = n.split()
a = ""
for i in range(len(p) - 1):
a += p[i][0] + "."
a += p[-1]
print(a)
Task – 35
Write a program that reads a string and returns a table of the letters of the alphabet in
alphabetical order which occur in the string together with the number of times each
BTCS 513-18 2232905
letter occurs.{USING DICTIONARY} Case should be ignored. A sample output of the
program when the user enters the data “ThiS is String with Upper and lower case
Letters”, would look this this:
A: 2
C: 1
D: 1
Task – 36
Write a function scalar_mult(s, v) that takes a number, s, and a list, v and returns
the scalar multiple of v by s
BTCS 513-18 2232905
def scalar_mult(s, v):
r = []
for n in v:
r.append(s * n)
return r
output = scalar_mult(7, [3, 0, 5, 11, 2])
print(output)
Task - 37
Given a tuple and a list as input, write a Python program to count the occurrences of all
items of the list in the tuple.
def c(t, l):
for x in l:
y = t.count(x)
print(x, ":", y)
a = ('a', 'a', 'c', 'b', 'd')
b = ['a', 'c']
c(a, b)
Task - 38
Given a list of words in Python, the task is to remove the Nth occurrence of the given
word in that list.
BTCS 513-18 2232905
def r(l, w, n):
c=0
for i in range(len(l)):
if l[i] == w:
c += 1
if c == n:
l.pop(i)
break
return l
a = ["apple", "banana", "orange", "apple", "grape", "apple", "kiwi", "banana", "apple"]
b = "apple"
c=3
d = r(a, b, c)
print(d)
Task – 39
Given a string, write a program to mirror the characters .i.e. change ‘a’ to ‘z’, ‘b’ to
‘y’, and so on.(Using Dictionary)
def m(s):
d = {}
for i in range(97, 123):
d[chr(i)] = chr(219 - i)
r = ''
for j in s:
if j in d:
r += d[j]
else:
r += j
return r
a = "hello world"
b = m(a)
print(b)
Task – 40
Merge following two Python dictionaries into one
dict1 = {'Ten': 10, 'Twenty': 20, 'Thirty': 30}
BTCS 513-18 2232905
dict2 = {'Thirty': 30, 'Fourty': 40, 'Fifty': 50}
Task – 41
Write a Python program that takes a text file as input and returns the number of words
of a given text file.
def c(f):
with open(f, 'r') as t:
x = t.read()
w = x.replace(',', ' ').split()
return len(w)
fn = input("Enter the name of the text file: ")
wc = c(fn)
print("Number of words:", wc)
file.txt
Hello,world! This is a test,with some,words.
Task – 42
Python program to count the number of lines in a text file.
def c(f):
with open(f, 'r') as t:
BTCS 513-18 2232905
r = t.readlines()
return len(r)
fn = input("Enter the name of the text file: ")
lc = c(fn)
print("Number of lines:", lc)
Task – 43
Count the occurrence of each word in given text file (Using dictionary)
def c(f):
d = {}
with open(f, 'r') as t:
for l in t:
w = l.split()
for x in w:
x = x.lower()
if x in d:
d[x] += 1
else:
d[x] = 1
return d
fn = input("Enter the name of the text file: ")
wc = c(fn)
for k, v in wc.items():
print(k, ":", v)
Task – 44
Eliminating repeated lines from a file. (Create another file and store unique lines in
that file)
def r_d(i, o):
BTCS 513-18 2232905
l=[]
with open(i, 'r') as f:
for line in f:
if line not in l:
l.append(line)
with open(o, 'w') as f:
for line in l:
f.write(line)
input_f = input("Enter input file name: ")
output_f = input("Enter output file name: ")
r_d(input_f, output_f)
file.txt
Hello
World
Hello
This is a test
World
op.txt
Hello
World
This is a test
Task – 45
Program to extract digits from a file and take the sum of those digits.
def d_sum(f):
s=0
with open(f, 'r') as x:
BTCS 513-18 2232905
for y in x:
for z in y:
if z.isdigit():
s += int(z)
return s
file_n = input("Enter file name: ")
total = d_sum(file_n)
print("Sum of digits is:", total)
file.txt
Hello 123
This is a test 456
Sum of digits: 789
Task – 46
Given an integer value, return a string with the equivalent English text of each digit.
For example, an input of 89 results in “eight-nine” being returned.
def convert(n):
d={
'0': 'zero',
BTCS 513-18 2232905
'1': 'one',
'2': 'two',
'3': 'three',
'4': 'four',
'5': 'five',
'6': 'six',
'7': 'seven',
'8': 'eight',
'9': 'nine'
}
res = []
for c in str(n):
res.append(d[c])
return '-'.join(res)
num = int(input("Enter a number: "))
result = convert(num)
print(result)
Task – 47
Write a program to find what percentage of words start with a vowel in a text file.
def perc_vowels(file):
vow = 'aeiouAEIOU'
total = 0
count = 0
BTCS 513-18 2232905
with open(file, 'r') as f:
for line in f:
words = line.split()
total += len(words)
for w in words:
if w and w[0] in vow:
count += 1
if total == 0:
return 0
return (count / total) * 100
file_name = input("Enter file name: ")
percentage = perc_vowels(file_name)
print("Percentage >>> ", percentage)
file.txt
An apple a day keeps the doctor away.
Every evening is a new beginning.
Task – 48
Write a program to Print all 7-letter words that start with th and end in ly.
def get_words(file):
w_list = []
file.txt
theory
thirsty
thimble
thinly
thugly
thorough
thingly
thatsly
Task – 49
Write a program to read from file and print All words >= 6 letters that start and end
with same three letters.
filename = input("Enter file name: ")
f = open(filename, 'r')
text = f.read()
f.close()
words = text.split()
BTCS 513-18 2232905
results = []
for word in words:
word = word.strip(",.!?\"'()[]{}").lower()
if len(word) >= 6 and word[:3] == word[-3:]:
results.append(word)
if results:
print("Words found:")
for word in results:
print(word)
else:
print("No words found.")
file.txt
The quick brown fox jumps over the lazy dog.
This is a test of the functionality of the program.
Banana is a fruit, and it is also a word that can be repeated: banana.
Doodoodoo and other fun words like ababab and lololol are interesting.
Task – 50
Write a program to read from file and print longest word that starts and ends with the
same letter.
file_name = input("Enter file name: ")
f = open(file_name, 'r')
data = f.read()
f.close()
words_list = data.split()
BTCS 513-18 2232905
longest = ""
for w in words_list:
w = w.strip(",.!?\"'()[]{}").lower()
if len(w) > 0 and w[0] == w[-1]:
if len(w) > len(longest):
longest = w
if longest:
print("Longest word is:", longest)
else:
print("No matching word found.")
file.txt
The quick brown fox jumps over the lazy dog.
This is a test of the functionality of the program.
Banana is a fruit, and it is also a word that can be repeated: banana.
Doodoodoo and other fun words like ababab and lololol are interesting.
Task – 51
Write a program to read from file and print all words that contain four alphabetically
consecutive letters.
file = input("Enter file name: ")
f = open(file, 'r')
text = f.read()
f.close()
words = text.split()
BTCS 513-18 2232905
found_words = [ ]
for w in words:
w = w.strip(",.!?\"'()[]{}").lower()
for i in range(len(w) - 3):
if (ord(w[i]) + 1 == ord(w[i + 1]) and
ord(w[i]) + 2 == ord(w[i + 2]) and
ord(w[i]) + 3 == ord(w[i + 3])):
found_words.append(w)
break
if found_words:
print("Words with four in a row are:", found_words)
else:
print("No words found.")
file.txt
The quick brown fox jumps over the lazy dogs.
I found the letters abcde in the word alphabetically.
Another example is the word defgh.
Task – 52
Write a function that uses the input dialog to prompt the user for a positive integer and
then checks the input to confirm that it meets the requirements.
def get_num():
while True:
try:
num = int(input("Enter a positive integer: "))
if num > 0:
BTCS 513-18 2232905
return num
else:
print("That's not a positive integer. Try again.")
except ValueError:
print("That's not a valid number. Try again.")
n = get_num()
print("You entered:", n)
Task – 53
Write a program that gets two command line arguments and checks that the first
argument represents a valid int number and second argument represents a float
number and display sum of those. Make useful feedback if they are not.
import sys
def main():
if len(sys.argv) != 3:
print("Please provide exactly two arguments.")
BTCS 513-18 2232905
return
arg1 = sys.argv[1]
arg2 = sys.argv[2]
try:
num1 = int(arg1)
except ValueError:
print(f"{arg1} is not a valid integer.")
return
try:
num2 = float(arg2)
except ValueError:
print(f"{arg2} is not a valid float.")
return
total = num1 + num2
print("The sum is:", total)
if __name__ == "__main__":
main()
Task – 54
Write a Python program to find all words which are at least 4 characters long in a
string.
import re
def find_long_words(s):
words = re.findall(r'\b\w{4,}\b', s)
return words
input_string = input("Enter a string: ")
BTCS 513-18 2232905
long_words = find_long_words(input_string)
print("Words with at least 4 characters:", long_words)
Task – 55
Write a Python program to remove everything from a string except alphanumeric
characters.
import re
def f(s):
return re.sub(r'[^a-zA-Z0-9]', '', s)
x = input("Enter a string: ")
y = f(x)
print("String with only alphanumeric characters:", y)
Task – 56
Write a Python program to check a string containing decimal with a precision of at
most 2.(e.g. 34.89(TRUE), 12.789(FALSE), 12(TRUE))
import re
def check_decimal(s):
return bool(re.fullmatch(r'\d+(\.\d{1,2})?$', s))
x = input("Enter a string: ")
result = check_decimal(x)
BTCS 513-18 2232905
if result:
print("Valid decimal with at most 2 decimal places (TRUE)")
else:
print("Invalid decimal (FALSE)")
Task – 57
Create Regular Expression for following”
Match for stings that start with From and characters (if any) followed by a two digit
number between 00 and 50, followed by : .
import re
def check_string(s):
pattern = r'^From.*\b([0-4][0-9]|50):$'
return bool(re.match(pattern, s))
BTCS 513-18 2232905
test_strings = [
"From something 25:",
"From 50:",
"From text 00:",
"From 51:"
]
for test in test_strings:
result = check_string(test)
print(f'"{test}" -> {result}')
Task – 58
Use a regular expression to write python program that take a date in a format, like
February 2, 2020 and convert it in an abbreviated format, mm/dd/yy i.e output should
be 2/6/20.
import re
def d(s):
BTCS 513-18 2232905
p = r'^(January|February|March|April|May|June|July|August|September|October|
November|December) (\d{1,2}), (\d{4})$'
m = re.match(p, s)
if m:
x, y, z = m.groups()
a={
"January": "1",
"February": "2",
"March": "3",
"April": "4",
"May": "5",
"June": "6",
"July": "7",
"August": "8",
"September": "9",
"October": "10",
"November": "11",
"December": "12"
}
b = a[x]
c = z[-2:]
return f"{b}/{y}/{c}"
else:
return "Invalid"
i = input("Enter a date >>> ")
r = d(i)
print("Converted date >>> ", r)