ITECH1400 Fundamentals of Programming: Palindrome and Anagram Code
VerifiedAdded on 2022/12/26
|7
|531
|1
Homework Assignment
AI Summary
This assignment solution for ITECH1400 Fundamentals of Programming focuses on implementing palindrome checks and anagram generation using Python. The solution includes pseudocode outlining the steps for both functionalities, followed by the corresponding Python code snippets. The palindro...
Read More
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.

Running head: ITECH1400 FUNDAMENTALS OF PROGRAMMING
ITECH1400 Fundamentals of Programming
Name of the Student
Name of the University
Authors note
ITECH1400 Fundamentals of Programming
Name of the Student
Name of the University
Authors note
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.

1ITECH1400 FUNDAMENTALS OF PROGRAMMING
Implementation of Palindrome check from the words of the file
Pseudocode
Step 1: Read file
Step 2: Read all the words or strings in the file.
Step 3: Initialize len variable to zero and a flag= zero
Step 4: While word[len] is not NULL
len++
Initialize “k” to zero , l to len-1
While k < (len/2)+1
If word[i] =word[J]
flag=0
else
Flag=1
Increment i , l Decrement
If flag=0
Print Palindrome
else
Print Not Palindrome
Stop
Implementation of Palindrome check from the words of the file
Pseudocode
Step 1: Read file
Step 2: Read all the words or strings in the file.
Step 3: Initialize len variable to zero and a flag= zero
Step 4: While word[len] is not NULL
len++
Initialize “k” to zero , l to len-1
While k < (len/2)+1
If word[i] =word[J]
flag=0
else
Flag=1
Increment i , l Decrement
If flag=0
Print Palindrome
else
Print Not Palindrome
Stop

2ITECH1400 FUNDAMENTALS OF PROGRAMMING
Code
with open('English.txt') as text:
count=0
for line in text:
line = line.strip()
lines = line[::-1]
if line == lines:
count+=1
print ('Following line in the text file is a Palindrome!')
print(count)
print(line)
Code
with open('English.txt') as text:
count=0
for line in text:
line = line.strip()
lines = line[::-1]
if line == lines:
count+=1
print ('Following line in the text file is a Palindrome!')
print(count)
print(line)

3ITECH1400 FUNDAMENTALS OF PROGRAMMING
Implementation of Palindrome check from the words of the file
Pseudocode for the program
Get all the strings in a list
Remove the spaces and convert to lowercase
Read next line as String2.
Remove the spaces in between and convert all in lowercase
STEP 1:
Get one by one letter of the consecutive strings and compare those letters of the next
string
For the previous word and compare with the first character of next word]
STEP 2: count the number of similar words among the two words.
[if string.i[1] = string.j[i]
Implementation of Palindrome check from the words of the file
Pseudocode for the program
Get all the strings in a list
Remove the spaces and convert to lowercase
Read next line as String2.
Remove the spaces in between and convert all in lowercase
STEP 1:
Get one by one letter of the consecutive strings and compare those letters of the next
string
For the previous word and compare with the first character of next word]
STEP 2: count the number of similar words among the two words.
[if string.i[1] = string.j[i]
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.

4ITECH1400 FUNDAMENTALS OF PROGRAMMING
add 1 to total string.i[i]
go to next character of the previous string]
STEP 3: check for all character/letters.
7[if total length of string= length(string1)
then return anagram=true
else
anagram check =false]
OUTPUT: returns true or false for check.
Code
def bd_dic(path):
adict = {}
f = open(path, "r")
for line in f.readlines():
line = line.strip()
key = sort_li(line)
if key in adict:
v = adict.get(key) + "," + line
add 1 to total string.i[i]
go to next character of the previous string]
STEP 3: check for all character/letters.
7[if total length of string= length(string1)
then return anagram=true
else
anagram check =false]
OUTPUT: returns true or false for check.
Code
def bd_dic(path):
adict = {}
f = open(path, "r")
for line in f.readlines():
line = line.strip()
key = sort_li(line)
if key in adict:
v = adict.get(key) + "," + line

5ITECH1400 FUNDAMENTALS OF PROGRAMMING
adict[key] = v
else:
adict[key] = line
return adict
def sort_li(line):
chars = [c for c in line]
chars.sort()
return "".join(chars)
def anagr(adict, line):
key = sort_li(line)
values = adict.get(key, "NONE")
return values.split(",")
adict = bd_dic(r"English.txt")
results = anagr(adict, "noid")
print("Anagrams for [noid]")
adict[key] = v
else:
adict[key] = line
return adict
def sort_li(line):
chars = [c for c in line]
chars.sort()
return "".join(chars)
def anagr(adict, line):
key = sort_li(line)
values = adict.get(key, "NONE")
return values.split(",")
adict = bd_dic(r"English.txt")
results = anagr(adict, "noid")
print("Anagrams for [noid]")

6ITECH1400 FUNDAMENTALS OF PROGRAMMING
print(results)
Screenshot
Following is the screen shot of the executed program.
print(results)
Screenshot
Following is the screen shot of the executed program.
1 out of 7

Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
© 2024 | Zucol Services PVT LTD | All rights reserved.