Question

I need help for this assignment. Thank you!!

# 5555555555555555555555555555555555555555555555555 # Returns the longest word (which has six or more # characters and contai# 6666666666666666666666666666666666666666666666666 # Remove triplets made up of three sequential # identical elements - 5 ma# score a hand of random dice throws - 4 marks 01 In a dice rolling game a players hand is made up of any number of random d

# 5555555555555555555555555555555555555555555555555 # Returns the longest word (which has six or more # characters and contains the letter, e) from # the parameter list - 4 marks Os Define the get_longest_e_word() function which is passed a list of strings as a parameter. The function returns the word in the list which has the most characters (i.e., the longest word) BUT only words which have 6 or more characters and contain the letter 'e' (or 'E') are considered. If two or more words in the list have the same number of characters as the longest word and both contain the letter 'e' (or 'E, the function should return the last word from the start of the list which has the most characters. If the parameter list is empty or if there are no 6 letter or longer words in the list which contain the letter 'e (or 'Ethe function should return the empty string. For example, the following code: print("1.", get_longest_e_word(l "Melissa", "Jessie", "Kath", "Amity", print("2.", get_longest_e_word(I "Jo","Jessie", "Penelope", "Jin", "Raeann print("3.", get_longest_e_word(l"Alan", "Melita", "Amity", "Rosalia". print("4. ", "*", get_longest_e_word(I Jo", "Jai", "Jen", "Jing", "Joey", Raeann" ])) "Pamelita" ])) "Rositta" "LeeAnne" ]) ) "Jess" ])," sep") print("5. ", "x**"., get_longest_e_word([])sep) print("6.", "***" + get_longest_e_word([" "]) + *" prints: 1. Melissa 2. Pamelita 3. Rosetta def get_longest_e_word (word_list): return""
# 6666666666666666666666666666666666666666666666666 # Remove triplets made up of three sequential # identical elements - 5 marks Define the remove_triplets() function which is passed a list of integers as a parameter. The function removes all triplets from the list (i.e., removes any three elements in the list which are exactly the same and are in sequence). For example, the following code: a_list- [6, 6, 6, 7, 6, 6, 6, 3, 3, 3, 8, 8, 8, 3] remove_triplets (a_list) print("1.", a_list) a_list [6, 6, 6, 7, 6, 6, 6, 6, 6] remove_triplets(a_list) print("2.", a_list) a_list [6, 6, 6, 7, 6, 6, 4, 3, 3, 3, 8, 8, 8, 3] remove_triplets(a_list) print ("3"", a-list) a-list= [1, 1, 1, 4, 4, remove_triplets(a_list) print("4.", a_list) 4, 1, 1, 1] remove_triplets (a_list) print("5."a list) prints: 1. 17, 3 2. 17, 6, 61 3. 17, 6, 6, 4, 3 4. def remove_triplets (a_list): pass
# score a hand of random dice throws - 4 marks 01 In a dice rolling game a player's hand is made up of any number of random dice throws and is, valued in the following way: .In this game a run is a sequence of dice values s 123, 12345, 1234, 1. ch is part of a run of dice starting from a 1 has a value which is equivalent to the dice number. The value of any dice which is part of a run is added to the hand score. If there is no 1 in a hand of dice, the score for the whole hand is o. A hand of dice can contain more than one run. tudy the following five example hands of dice and their corresponding valuation. 15, 3, 2, 5, 4, 5, 6, 4, 3] has value 0 [1] and a second run with just [1]) Make sure you understand how the hands are valued: 31 1 4 61 has value 2 (contains one run with just the dice 5, 3, 2, 2, 6, 4, 5, 1, 4] has value 21 (contains one run with the dice [1, 2, 3, 4, 5, 6]) 12, 1, 1, 1, 2, 3, 3, 1, 3, 2] has value 19 (contains three separate runs with the dice 23 and a second run with the dice 13, 4, 1, dice [1, 2, 3, 4, 5, 61, a second run with [1, 2, 3, 4, 5] and a third run with the dice [1]). 5, 2, 1, 5, 1, 2, 3, 4, 61 has value 37 (contains one run with the Complete the get_dice_score() function which is passed a list of dice thr eturns the value of the hand according to the rules described above. def get_dice_score(list_of_dice): return 0
0 0
Add a comment Improve this question Transcribed image text
Answer #1

I am attaching the screenshot of code for indentation

Q5.
def get_longest_e_word(word_list):
if len(word_list)==0:
return ""
to_return=""
for elem in word_list:
if len(elem)>=6 and "e" in elem:
if len(elem)>=len(to_return):
to_return=elem
return to_return
def get longest e word (word list): if len(word list)--0: return to return- for elem in word 1ist: if len(elem)>-6 and e

Q6.
def remove_triplets(arg_list):
index_list=[]
idx=0
while idx < len(arg_list)-2:
if arg_list[idx]==arg_list[idx+1] and arg_list[idx+1]==arg_list[idx+2]:
index_list.extend([idx,idx+1,idx+2])
idx+=2
idx=idx+1
index_list.reverse()
for i in index_list:
arg_list.pop(i)

Q7.
def get_dice_score(list_of_dice):
if 1 not in list_of_dice:
return 0
count=[]
for i in [1,2,3,4,5,6]:
count.append(list_of_dice.count(i))
for i in range(len(count)):
for j in range(i+1,len(count)):
if count[j]>count[i]:
count[j]=count[i]
score=0
for i in range(len(count)):
score=score+count[i]*(i+1)
return score
def get_dice_score(list_of_dice): if 1 not in list_of_dice: count-[ for i in [1,2,3,4,5,6]: for i in range(len (count)): retu

Add a comment
Know the answer?
Add Answer to:
I need help for this assignment. Thank you!! # 5555555555555555555555555555555555555555555555555 # Returns the longest word (which has six or more # characters and contains the letter, e) from # the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Complete the get_mid_letter() function which is passed a list of strings as a parameter. The function...

    Complete the get_mid_letter() function which is passed a list of strings as a parameter. The function returns a string made up of the concatenation of the middle letter of each word from the parameter list. The string returned by the function should be in lowercase characters. If the parameter list is an empty list, the function should return an empty string For example Test Result print("1.", get mid_letter"Jess", "Cain", Amity", "Raeann"])) 1. siia Answer (penalty regime: 0 %) 1 -Idef...

  • Define a function called get_n_largest(numbers, n) which takes a list of integers and a value n...

    Define a function called get_n_largest(numbers, n) which takes a list of integers and a value n as parameters and returns a NEW list which contains the n largest values in the parameter list. The values in the returned list should be in increasing order. The returned list must always be of length n. If the number of values in the original list is less than n, the value None should be repeated at the end of the returned list to...

  • Hey guys I need help with this assignment. However it contains 7 sub-problems to solve but I figured only 4 of them can...

    Hey guys I need help with this assignment. However it contains 7 sub-problems to solve but I figured only 4 of them can be solved in one post so I posted the other on another question so please check them out as well :) Here is the questions in this assignment: Note: Two helper functions Some of the testing codes for the functions in this assignment makes use of the print_dict in_key_order (a dict) function which prints dictionary keyvalue pairs...

  • Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a...

    Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a boolean indicating whether the parameter string is a valid date or not. The first two lines of the function are: month_names = ["January", "February", "March","April", "May", "June", "July", "August", "September", days_in_month = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) where month_names is a list of valid month names, and days_in_month is a list which contains the maximum day number...

  • Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a...

    Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a boolean indicating whether the parameter string is a valid date or not. The first two lines of the function are: month_names = ["January", "February", "March", "April", "May", "June", "July", "August", "September", days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] where month_names is a list of valid month names, and days_in_month is a list which contains the maximum day...

  • Creat a C Program that Reads words from a file called words, which contains one word...

    Creat a C Program that Reads words from a file called words, which contains one word per line.Each word has maximum length to M.The number of words in the file is equal to N. Incert each word to Binary Search Tree with node name dictionary.Each node of the tree must contain one word.The left child must contain a word that it is lexicographically smaller while the right child contains a lexicographically bigger one. 1) When you finish reading the file,...

  • [Python] I have the following function that removes all non-numerical characters from a string: d...

    [Python] I have the following function that removes all non-numerical characters from a string: def remove_non_numeric(s):    seq_type= type(s) return seq_type().join(filter(seq_type.isdigit, s)) And I need help implementing it into this function: def list_only_numbers( a_list ) : # Create a new empty list. # Using a loop (or a list comprehension) # 1) call remove_non_numeric with a list element # 2) if the return value is not the empty string, convert # the string to either int or float (if it contains...

  • Hey guys I need help with this question with 3 sub-problems. f test remove short synonyms () Define the remove shorti s...

    Hey guys I need help with this question with 3 sub-problems. f test remove short synonyms () Define the remove shorti synonyms function which is passed a dictionary as a parameter- The keys of the parameter dictionary are words and the corresponding values are 1ists of synonyms (synonyms are words which have the same or nearly the same meaning). The function romoves all the eynonyme which have ous than 8 charactors from each corresponding list of synonyms-As well, the funet...

  • Use Python: Dice Rolls Create a function named build_roll_permutations which returns all 36 permutations of rolling...

    Use Python: Dice Rolls Create a function named build_roll_permutations which returns all 36 permutations of rolling two six sided dice. That is, each dice has a number 1 through 6 on one of its sides. The return value is a list which contains tuples. Each tuple represents a possible dice roll of two dice. Card Deck Create a function named build_deck that returns a full deck of cards. The cards are created by a rank and a suit (e.g. 2♡)....

  • Assignment 1 In this assignment you will be writing a tool to help you play the...

    Assignment 1 In this assignment you will be writing a tool to help you play the word puzzle game AlphaBear. In the game, certain letters must be used at each round or else they will turn into rocks! Therefore, we want to create a tool that you can provide with a list of letters you MUST use and a list of available letters and the program returns a list of all the words that contain required letters and only contain...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT