Design and explanation of the procedure:
Following is a step by step process for solving the problem:
1. Take some input string from the user.
2. Convert the characters in the string provided by the user to
lowercase.
3. Define an empty dictionary having character as key and its
frquency as its value
4. For the next character in the given string do the
following
5. if the character is an alphabet, go to step 6, otherwise go to
step 4.
6. if the character is present in the dictionary, increase its
count
7. Else if the character is not present, insert it and make its
count as 1.
8. Go to step 4 for the next character in the string. If there are
no more characters, go to next step.
9. For each key in the dictionary, sorted accourding to the
keys,
10. print the key and the value.
Code:
def lettercount():
print("Enter some letters >>>")
str1=raw_input() #taking input
str1=str1.lower() #converting to lower case
dict = {}
for n in str1:
if n.isalpha(): #if n is an alphabet
keys = dict.keys()
if n in keys: #if n present in dictionary increase its count
dict[n] += 1
else:
dict[n] = 1
for key in sorted(dict.iterkeys()):
print "%s: %s" % (key, dict[key])
lettercount()
Sample running of the program:
$python main.py
Enter some letters >>>The cat in the hat
a: 2
c: 1
e: 2
h: 3
i: 1
n: 1
t: 4
Exercise 7.1 (lettercount.py, design). Before attempting to program lettercount.py, create a file called design that includes...
1. Write a Python program, in a file called concat_strings.py, that includes the following functions: orderedConcat, a recursive function that takes two alphabetically-ordered strings and merges them, leaving the letters in alphabetical order. Note that the strings may be different lengths. a main method that inputs two ordered strings and calls the orderedConcat method to return a resulting merged, ordered string. Your main method should print the two input strings and the result. Note: You may not use any of...
Need help writing four short recursive programs: Write a program called Permutations.java that takes an integer command-line argument, n, and enumerates all permutations of the first n letters in the English alphabet. Be sure to handle exceptions of the types: i) bad user input (i.e., double, string), ii) n > 26 or n < 0. Write a program called PermutationsK.java that takes two integers, n and k, as command-line arguments and prints out all P(n,k) permutations that contain exactly k...
(IN JAVA) Write a program named Review.java and implement the following methods: public static boolean isValidTicTacToeBoardString(String str) This method takes as its parameter a String that contains 9 characters representing the status of the Tic Tact Toe game. The String is mixed with X, O, x, o, and other letters. The first three letters represent the first row, letter 4 through letter 6 represent the second row, and the rest for the last row. To be considered as a valid...
Create a new program in Mu and save it as ps4.5.2.py and take the code below and fix it as indicated in the comments: # Do not change the line of code below. It's at the top of # the file to ensure that it runs before any of your code. # You will be able to access french_dict from inside your # function. french_dict = {"me": "moi", "hello": "bonjour", "goodbye": "au revoir", "cat": "chat", "dog": "chien", "and": "et"} #...
Please write a java program with a input file "jabberwock.txt", and output the "output.txt" with following requirement. You and your partner will be writing a simple Java program that implements some basic file I/O operations. You can use this code as the basis for some of your next project. FIRST: Write code that prompts the user for the name of a text file, opens that file if it exists and reads the file one line at a time printing each...
JAVA PROJECT Part 1 - Normalize Text The first thing we will do is normalize the input message so that it’s easier to work with. Write a method called normalizeText which does the following: Removes all the spaces from your text Remove any punctuation (. , : ; ’ ” ! ? ( ) ) Turn all lower-case letters into upper-case letters Return the result. The call normalizeText(“This is some \“really\” great. (Text)!?”) should return “THISISSOMEREALLYGREATTEXT” Part 2 - Obfuscation...
1. Write a C++ program called Password that handles encrypting a
password.
2. The program must perform encryption as follows:
a. main method
i. Ask the user for a password.
ii. Sends the password to a boolean function called
isValidPassword to check validity.
1. Returns true if password is at least 8 characters long
2. Returns false if it is not at least 8 characters long
iii. If isValidPassword functions returns false
1. Print the following error message “The password...
The skeleton code (starter file) for the problem is pasted
below:
def phoneNumber(letters):
result = ""
# ADD YOUR CODE HERE
return result
def loadEvents(filename):
events = {}
# ADD YOUR CODE HERE
return events
def timeline(events):
# ADD YOUR CODE HERE
return
# DO NOT modify or remove the code below! We will use it for
testing.
if __name__ == "__main__":
# Problem 1: Decoding Telephone Numbers
ph = input("Enter the text to translate: ")
print("The corresponding phone number...
CIST 1305 – Program Design and Development Chapter 4 Assignment #7 [Decisions/If Statements & Loops] (50 Points) Please do the following exercises: Pastoral College is a small college in the Midwest. Design the pseudo-code for a program that accepts a student name, major field of study, and grade point average. Display a student’s data with the message “Dean’s list” if the student’s grade point average is above 3.5, “Academic probation” if the grade point average is below 2.0, and no...
In Java,enhace the program base on the first one. 1. You are going to design (and code) a class called Name. The class Name will contain three properties: first, the first name which is a String initial, the middle initial, which is a single character. last, the last name, which is a String The class has three constructors: A default constructor, which accepts no parameters, calls constructors for the first and last name and sets the initial equal to a...