CC Assingment 1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Muhammad Hassaan Azhar

(022-16-113313)

import re
RE_Numerals = "^(\d+)$"
Articles=[]
Pronouns=[]
Numbers=[]
re1="^[-+]?[0-9]*\.?[0-9]+$"
re2="^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$"
with open('C:\\Users\\MRC\\Downloads\\Music\\dd.txt', 'r') as file:
f = open("C:\\Users\\MRC\\Downloads\\Music\\dd.txt", "a")
count = 0
while True:
# this will read each character
# and store in char
char = file.read(1)
if char.isspace():
count += 1
if not char:
break
file.close()
with open('C:\\Users\\MRC\\Downloads\\Music\\dd.txt', 'r') as file:
for line in file:
for word in line.split():
if(word=="a"or word=="an" or word=="the"):
Articles.append(word)
elif(word=="I" or word== "we" or word== "you" or word == "He" or word == "she" or
word == "it" or word== "they"):
Pronouns.append(word)
elif(word.isnumeric()):
Numbers.append(word)
print("\nArticles {",Articles,"} -> <Article, lexical value>")
print("\nPronouns {", Pronouns, "} -> <Pronoun, lexical value>")
print("\nNumbers {",Numbers,"} -> <Number, lexical value>")
print("\nSpaces ",count)
f.write("\nArticles {")
f.write(str(Articles))
f.write("} -> <Article, lexical value>")
f.write("\nPronouns {")
f.write(str(Pronouns))
f.write("} -> <Pronoun, lexical value>")
f.write("\nNumbers {")
f.write(str(Numbers))
f.write("} -> <Number, lexical value>")
f.write("\nSpaces ")
f.write(str(count))
import re
import nltk
input_program = input("Enter Your Code: ");
input_program_tokens = nltk.wordpunct_tokenize(input_program);
print(input_program_tokens);
RE_Numerals = "^(\d+)$"
RE_Identifiers = "^[a-zA-Z_]+[a-zA-Z0-9_]*"
for token in input_program_tokens:
if(re.findall(RE_Numerals,token)):
print(token, "-------> Number")
elif(re.findall(RE_Identifiers,token)):
print(token, "-------> Identifiers")

You might also like