Questions: 5 831

Answers by our Experts: 5 728

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Write the function sum() with four parameters the calculates the arguments provided and returns their sum

Parameters four variables of type float

Returns the sum of type float

Use the default argument 4 to declare the last two parameter of the function sum() test the function sum() by calling it by three possible methods use random integers as arguments


consider the invert_dict function from Section 11.5 of your textbook. 

# From Section 11.5 of: 

# Downey, A. (2015). Think Python: How to think like a computer scientist. Needham, Massachusetts: Green Tree Press. 


def invert_dict(d):

   inverse = dict()

   for key in d:

      val = d[key]

     if val not in inverse:

        inverse[val] = [key]

     else:

        inverse[val].append(key)

   return inverse 


Modify this function so that it can invert your dictionary. In particular, the function will need to turn each of the list items into separate keys in the inverted dictionary. 

Run your modified invert_dict function on your dictionary. Print the original dictionary and the inverted one. 

Include your Python program and the output in your Learning Journal submission. 



Python Program


Write a program to print the following, Given a word W and pattern P, you need to check whether the pattern matches the given word.The word will only contain letters(can be Uppercase and Lowercase). The pattern can contain letters, ? and *.


? : Can be matched with any single letter.

* : Can be matched with any sequence of letters (including an empty sequence).


If the pattern matches with the given word, print True else False.


Sample Input1

3

Hello *l?

Hell He?ll

Hell ?*

Sample Output1

True

False

True


Sample Input1

3

Hello Hell*

Hell He*ll

Hell hell*

Sample Output1

True

True

False


Search Game

A grid of letters may contain a word hidden somewhere within it. The letters of the word may be traced from the starting letter by moving a single letter at a time, up, down, left or right. For example, suppose we are looking for the word BISCUIT in this grid:

0 1 2 3


0 B I T R


1 I U A S

2 S C V W


3 D O N E

The word starts in the top left corner, continues downwards for 2 more letters, then the letter to the right followed by 2 letters moving upwards, the final letter at the right of the penultimate one.

Write a program in which we give target word and a grid of letters as input returns a list of tuples, each tuple being the row and column of the corresponding letter in the grid (numbered from 0). If the word cannot be found, output the string Not present

input1:

after

4

a b c d

f e f g

t e r r

a b i j

Output: [(0, 0),(1, 0),(2, 0),(2, 1),(2, 2)]


input2:

search

4

s e a c

r c c c

h e e e

h e e e

output: Not Present


Next consider the invert_dict function from Section 11.5 of your textbook. 

# From Section 11.5 of: 

# Downey, A. (2015). Think Python: How to think like a computer scientist. Needham, Massachusetts: Green Tree Press. 

def invert_dict(d):

   inverse = dict()

   for key in d:

      val = d[key]

     if val not in inverse:

        inverse[val] = [key]

     else:

        inverse[val].append(key)

   return inverse 

Modify this function so that it can invert your dictionary. In particular, the function will need to turn each of the list items into separate keys in the inverted dictionary. 

Run your modified invert_dict function on your dictionary. Print the original dictionary and the inverted one. 

Include your Python program and the output in your Learning Journal submission. 

Describe what is useful about your dictionary. Then describe whether the inverted dictionary is useful or meaningful, and why. 


Create a Python dictionary that returns a list of values for each key. The key can be whatever type you want. 

Design the dictionary so that it could be useful for something meaningful to you. Create at least three different items in it.


Python Program


Write a program to print the following, Given a word W and pattern P, you need to check whether the pattern matches the given word.The word will only contain letters(can be Uppercase and Lowercase). The pattern can contain letters, ? and *.


? : Can be matched with any single letter.

* : Can be matched with any sequence of letters (including an empty sequence).


If the pattern matches with the given word, print True else False.


Sample Input1

3

Hello *l?

Hell He?ll

Hell ?*

Sample Output1

True

False

True


Sample Input1

3

Hello Hell*

Hell He*ll

Hell hell*

Sample Output1

True

True

False



Write a program to print the following output.


Input

The first line contains a string.

The second line contains some space-separated strings.


Output

The output should be a single integer.


Explanation

scramble word = "tacren"

guessed words = ["trance", "recant"]


Since "trance" and "recant" both have length 6 then you score 54 pts each.

So the output is 108.


Sample Input1

rceast

cat create sat

Sample Output1

2


Sample Input2

tacren

trance recant

Sample Output2

108



Ask the use if they want a cup of tea. If they replay with “no” or “n” repeat the question. Once the loop stops display the message “Sorry,we have run out of tea”

Ask the user to input a number and then ask if they want to double the number. If they answer “y”multiply the number by 2 and display the answer. Keep repeating this loop, doubling their number each time, until they no longer reply “y”.

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS