Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Write a function called repeat_end that accepts a string and an integer (n) as arguments and returns a string made of n repetitions of

1. Write a function called repeat_end that accepts a string and an integer (n) as arguments and returns a string made of n repetitions of the last n characters of the string. For example, if the string is 'program' and n is 4, the returned string should be 'gramgramgramgram'. Assume that the length of the string is at least n.

2.

Common Suffixes

Write a predicate function called ends_in_common_suffix that accepts a string argument that represents a word and returns True if the word ends in one of the following common suffixes: 'ly', 'ion', 'ed', or 'able'. Do NOT use an if statement in your solution.

3.

String Sandwich

Write a function named make_sandwich that accepts two strings as arguments and returns a string composed of the shorter string on either side of the larger. For example, if the two arguments are 'bread' and 'turkey', the combined string would be 'breadturkeybread'. If the two arguments have equal length, surround the second argument by the first.

4.

Set Random 10 To 15

Write code that uses the random module to set the value of a variable named num to a random integer between 10 and 15, inclusive. You may assume that the random module has already been imported.

5.

Random 1 to 10 Function

Write a function called random10 that accepts no arguments and returns a random integer in the range 1 to 10, inclusive. You may assume that the random module has been imported.

6.

Count the Heavy Packages

Given a list of integers called package_weights, write code that counts the number of values in the list that are greater than 50. Store the result in a variable named heavy_count. Assume that the list has been initialized.

7.

Concatenate List Elements

Write a function called concat_list that accepts a list of strings as an argument and returns a string made up of all elements in the list concatenated together in order. For example, if the argument is ['one', 'two', 'three'], the return value would be 'onetwothree'.

Check Lottery Numbers

Write code that checks a list of lottery numbers stored in the variable my_numbers against a list of winning numbers stored in the variable todays_pick. Assign the number of matching values to the variable num_matches. The numbers may be in any order in either list. Assume both lists have already been initialized.

Please answer all of them in Python please, thanks!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago