In: Computer Science
Level Max number of nodes
.. …
n ??
The maximum number of nodes on level n of a binary tree is :
A 2^(n-1) B 2^n
C 2^(n+1) D 2^[(n+1)//2]
In the above answers, the operator '^' indicates power (or exponent).
Hint: Check your answer using level 5 and 6 data
(+30) 4. 5. 9. Worth 4 points all others 3 points
Using the lists a and vowels as defined:
a = [ "Euclid", "Archimedes",
"Newton”, “Descartes",
"Fermat", "Turing",
"Euler", "Einstein",
"Boole", "Fibonacci",
"Nash"]
vowels = ['A', 'a',
'E', 'e', 'I',
'i', 'O', 'o',
'U','u']
write a Python program that will
Output should be the string “EANDFTEEBFN”
See 9 in the output and consider using the + operator Must use a loop
Output should be the string “dsnstgrneih”
See 10 in the output Must use a loop
For 7 and 8 use sort() and reverse() functions as needed
Thanks for the question, here are the code for all the sub parts with comments
======================================================================
a = [ "Euclid", "Archimedes",
"Newton", "Descartes",
"Fermat", "Turing",
"Euler", "Einstein",
"Boole", "Fibonacci",
"Nash"]
vowels = ['A', 'a',
'E', 'e', 'I',
'i', 'O', 'o',
'U','u']
#1. Display the longest name (done #12 below
)
longest_word=''
shortest_name=a[0]
for word in a:
if
len(longest_word)<len(word):
longest_word=word
if
len(shortest_name)>len(word):
shortest_name=word
#1. Longest Name
print('Longest Name:
{}'.format(longest_word))
#2. Display the shortest name
print('Shortest Name:
{}'.format(shortest_name))
#3. Display the number of names in the
list
print('Number of names: {}'.format(len(a)))
#4. Display a string that consists of the
first letter from each of 11 names in the list a
initials=''
for word in a:
initials=initials+word[0]
print('Initials: {}'.format(initials))
#5. Display a string that consists of the
last letter from each of 11 names in the list a
last_letters=''
for word in a:
last_letters=last_letters+word[-1]
print('Last Letters:
{}'.format(last_letters))
#6. Ask the user for a letter. Display the
number of times the letter appears in the list
letter = input('Enter a letter: ')
count_occurences=0
for word in a:
count_occurences+=word.count(letter)
print('Letter: {} occurs {}
times'.format(letter,count_occurences))
#7. Sort list a and display the
list
a.sort()
print('Sorted list',a)
#8. Sort the list in reverse order and
display the list
a.sort()
a.reverse()
print('Reverse Sorted', a)
#9. Display the number of vowels using the
vowels list in the list a
vowels_count=0
for word in a:
for vowel in
vowels:
vowels_count+=word.count(vowel)
print('There are {} vowels in the
list'.format(vowels_count))