« first day (914 days earlier)      last day (1135 days later) » 

5:14 AM
@JohnRennie Sir i need help in that cs test , I told you yesterday.
 
OK ...
 
I sent you an image .
This question is very similar to q13 in my assignment pdf , if you still have it.
I have the code for q13.
 
# Define the name we use for the file containing the text
TEXTFILE = "q13.txt"

# For the dictionary we'll use a global variable
vowelcount = {}

# Read the text
try:
    f = open(TEXTFILE)
    contents = f.read()
    f.close()
except FileNotFoundError:
    print("Cannot open file: " + TEXTFILE)
    exit()

# Lowercase the text so we need only check for 'a', 'e', 'i', 'o' and 'u'
contents = contents.lower()

# Initialise the dictionary
vowelcount["a"] = 0
vowelcount["e"] = 0
vowelcount["i"] = 0
 
Yes.
 
So the only difference is that you need to read a word at a time instead of a letter at a time.
 
5:20 AM
Sir not to be very rude but this is a test and i have to submit the test by 12.00 pm ist.
 
Give me a moment ...
 
5:33 AM
# Define the name we use for the file containing the text
TEXTFILE = "exam.txt"

# For the dictionary we'll use a global variable
worddict = {}

# Read the text
try:
    f = open(TEXTFILE)
    contents = f.read()
    f.close()
except FileNotFoundError:
    print("Cannot open file: " + TEXTFILE)
    exit()

# Lowercase the text
contents = contents.lower()

# Split the text into a list words
words = contents.split()

# Go through all the words in the list
numwords = 0
for w in words:
    numwords = numwords + 1
Try that
I used this data for testing:
mary had a little lamb mary little little
D:\rhs\Python\Bhavay>python exam.py
Number of words in file =  8
Most frequent word =  little
Number occurrences =  3
 
in my computer it is saying can't open exam.txt
 
You need to put the text into a file called exam.txt
 
I know.
THis is the text in exam.txt file
Part Of Speech — Verb.
Noun — Effacement.
Adjective — Effaceable.
Pronunciation —
E as in erase,
ff as in office,
ace as in face.
Meaning —
To erase something. OR
To remove something from one's memory. OR
To make someone unimportant or insignificant.
Etymology —
The word efface has been derived from the French word effacer meaning to pardon someone.
Mnemonic —
She had to efface the mark from her face with the towel.
Sentences —
The teacher asked the student to efface the words written on the blackboard. (Noun, to erase or remove something)
 
D:\rhs\Python\Bhavay>python exam.py
Number of words in file =  254
Most frequent word =  —
Number occurrences =  18
 
Although I need to write this code by hand , so shall I copy it first and fix it later?
 
5:42 AM
Ah, we need to eliminate words that don't contain any letters. The code is treated " - " as a word.
The file must be in the wrong place.
It opens fine here.
 
I will fix it later then. One last question .
 
Yes?
That's similar to one of the question as well.
 
Yes.
Although , i don't know what's a bubble sort ?
 
So selection sort ?
 
5:47 AM
A bubble sort goes through the list and swaps pairs of elements if the left is larger than the right.
It is similar to a selection sort but it is simpler (and slower)
Do you want me to write something for that question?
 
okay.
@JohnRennie Yes sir.
 
OK I'll get on it
 
@JohnRennie Sir in this question line 37
why is there comment before for ?
 
I put in those line for debugging. They print all the words and the number of times the word was found.
I commented them out after I had got the program working because we don't want the words printed in the final version.
 
okay got it.
 
6:07 AM
This is Q1 so far:
# Print the options menu

def PrintMenu():
    print("1. Sort employees")
    print("2. Search for name")
    print("3. Exit")
    print("Choose option: ", end = "")

# Get an integer from the user
# This function always returns an integer. It will keep looping until
# a valid integer is typed.

def GetInt():
    while True:
        s = input()
        try:
            i = int(s)
            return i
        except:
            print("You entered an invalid number. Please try again.")


########################################################################
 
And how much is left?
 
I need to wruite the code to do the search and the sort. I'll do that now.
 
Okay sir.
 
6:21 AM
Final version
# Print the options menu

def PrintMenu():
    print("1. Sort employees")
    print("2. Search for name")
    print("3. Exit")
    print("Choose option: ", end = "")

# Get an integer from the user
# This function always returns an integer. It will keep looping until
# a valid integer is typed.

def GetInt():
    while True:
        s = input()
        try:
            i = int(s)
            return i
        except:
            print("You entered an invalid number. Please try again.")

# Print employees
This is a fixed version of th first program that excludes "words" like "-" that don't contain any letters:
# Define the name we use for the file containing the text
TEXTFILE = "exam.txt"

# For the dictionary we'll use a global variable
worddict = {}

# Function to check the token is a word i.e. contains at least one letter
def isword(w):
    for c in w:
        if c.isalpha():
            return True
    return False

# Read the text
try:
    f = open(TEXTFILE)
    contents = f.read()
    f.close()
except FileNotFoundError:
    print("Cannot open file: " + TEXTFILE)
    exit()

# Lowercase the text
 
@JohnRennie Works perfectly.
 
:-)
 
 
6 hours later…
12:11 PM
54 messages moved from Room for B & J
 

« first day (914 days earlier)      last day (1135 days later) »