Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Computer Science Problem with Python Problem 1 Write a function that takes a list of numbers as input. The function should return the product of

Computer Science Problem with Python

Problem 1 Write a function that takes a list of numbers as input. The function should return the product of all of the numbers in the input list.

E.g. product([3,2,5,2]) 60

Problem 2 Write a function that takes an integer n as input and returns a list of n random integers in the range [1,100].

E.g. makeRandomList(5) [56,88,1,42,12]

Problem 3 Write a function that takes a list as input. The function should return a new list with all of the duplicate elements in the original list removed. The returned list should contain only the first instance of each digit from the input list (in their original order).

E.g.: removeDuplicates([1,5,3,1,2,7,1,3,5]) [1,5,3,2,7]

Problem 4 Write a function that takes a string as input and returns True if the string is a palindrome. A palindrome is a word or phrase that spells the same thing forwards or backward (ignoring spaces).

E.g.: palindrome('noon') True palindrome('racecar') True palindrome('taco cat') True palindrome('python is fun') False

Problem 5 Write a function called l337encode() that takes a string as an argument and returns a string in which the following substitutions have been made.

A or a 4

B or b 8

E or e 3 L or l 1

O or o 0

S or s 5

T or t 7

All other letters should be capitalized. Note, there are several ways to solve this. The easiest uses string.replace(), but for a greater challenge, solve this using a loop and comparisons, or a dictionary. E.g.: l337encode("Bob is an eleet haxor") "808 I5 4N 31337 H4X0R" Problem 6 Write a function called remove() that takes two strings as arguments: the source, and the token. The function should remove all instances of the token from the source string. Note: The built-in string.replace() is particularly well suited to this task. For additional practice, solve this problem using string.find() and string slices ([:]) instead. E.g.: remove("This is as it is.", "is") 'Th as it .'

Problem 7 Write a function that takes a string s and an integer n as arguments. The function should then return the nth word from that string (or an empty string if no such word exists). As a bonus challenge, try solving this without the use of the str.split() method. For an even greater challenge, try solving it without the str.find() method as well.

E.g.: nthWord("One two three four five six seven", 3) 'three' nthWord("Hello",3) ''

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

Visual Basic6 Database Programming

Authors: John W. Fronckowiak, David J. Helda

1st Edition

0764532545, 978-0764532542

More Books

Students also viewed these Databases questions

Question

Describe the sources of long term financing.

Answered: 1 week ago