Using python write a program able to a Euclid Archimedes N
Using python, write a program able to:
a = [ \"Euclid\", \"Archimedes\", \"Newton\",\"Descartes\", \"Fermat\", \"Turing\", \"Euler\", \"Einstein\", \"Boole\", \"Fibonacci\", \"Nash\"]
1. Display the longest name
2. Display the shortest name
3. Display a string that consists of the first letter from each of 11 names in the list a
4. Display a string that consists of the last letter from each of 11 names in the list a
5. Ask the user for a letter. Display the number of times the letter appears in the list
6. Sort list a i.e. the first name in the list should be Archimedes; last name is Turing
7. As you process the array make sure you are using a while , for etc loop
i would appreciate if i can get the code
Solution
Here is the main.py code:
-----------------------------------------------------------------------------------------------------------
a = [ \"Euclid\", \"Archimedes\", \"Newton\",\"Descartes\", \"Fermat\", \"Turing\", \"Euler\", \"Einstein\", \"Boole\", \"Fibonacci\", \"Nash\"]
longest_name = a[0];
shortest_name = a[0];
first_letter_string = \"\";
last_letter_string = \"\";
user_letter = \'\';
user_letter = raw_input(\"Enter the letter you want to search (If entered more than one, only first character will be considered): \");
user_letter_count = 0;
if len(user_letter) > 1:
user_letter = user_letter[0];
for name in a:
if len(name) > len(longest_name):
longest_name = name;
if len(name) < len(shortest_name):
shortest_name = name;
first_letter_string += name[0];
last_letter_string += name[len(name)-1];
if user_letter != \'\':
for char in name:
if user_letter == char:
user_letter_count += 1;
print \"Longest name: \" + longest_name;
print \"Shortest name: \" + shortest_name;
print \"First letter string: \" + first_letter_string;
print \"Last letter string: \" + last_letter_string;
if user_letter != \'\':
print \"Number of times user letter {} appeared is {}\".format(user_letter,user_letter_count);
b = a;
b.sort();
print(\"Sorted List: \");
print b;
---------------------------------------------------------------------------------
PLEASE THUMBS UP IF SATISFIED ^_^

