easy-python3-questions

###Q1:

We will say that a string is boring if the same sequence of three letters appears more than once in the string. For example, the following string is boring:

  • JONATHON LIKES PYTHON

But these strings are not boring:

  • ALICE LIKES PYTHON
  • I HEAR THE ART

Write a program that determines if a given string is boring. You can assume that the string only contains upper-case letters and spaces.

def boring(s):

###Q2a:

Inky, Blinky, Pinky and Clyde are going to the local arcade, but they have overly complicated rules for determining who gets to play pinball.

  • Inky gets to play pinball on days that start with the letter “T”.
  • Blinky gets to play pinball on days that follow days that start with the letter S. n
  • Pinky always gets to play pinball on a day of the month divisible by 4, regardless of what day of the week it is. n
  • Clyde only gets to play pinball if Inky and Blinky have already played that week, and if Pinky does not get to play.

Write a python function which takes two arguments (the day of the week in string format and the day of the month in numerical format) and returns the name of the person that gets to play pinball that day.

def pinball(dayOfWeek, dayOfMonth) :

###Q2b:

Using the function you wrote in part 3a), write another function that, given the number of days in the month, and the day that the month starts on, the number of days that Inky Blinky Pinky and Clyde will get to play pinball in that month.

The function provided will increment the day of the week to the next correct day. Use it wisely!

def incDay(day) :

if (day == “Sunday”) :

return “Monday”

elif (day == “Monday”) :

return “Tuesday”

elif (day == “Tuesday”) :

return “Wednesday”

elif (day == “Wednesday”) :

return “Thursday”

elif (day == “Thursday”) :

return “Friday”

elif (day == “Friday”) :

return “Saturday”

elif (day == “Saturday”) :

return “Sunday”

def playCount(startingDay, daysInMonth) :

# your code here

###Q2c:

Who gets to play the most pinball on any given month?

def question3c ():

# return “Inky”

# return “Blinky”

# return “Pinky”

# return “Clyde”

###Q3:

The bound of a list of numbers is a pair with the smallest and largest number. Write a Python function bound(l) that takes non-empty list l and returns its bound as a list or tuple.

def multipleSum(N, x, y):

###Q4:

Write a function subsetsum(l, s) that determines if there are any two numbers in the list l that add to s.

e.g., for ([1, 2, 3], 5), it would be True, since 2 + 3 = 5.
([1, 2, 3], 6) would be false since there are no two numbers that add to six in the list (you cannot use the same value of three twice). On the contrary, if the input were ([1, 2, 3, 3], 6), this would be true because there are two 3s in the list.

def subsetsum(l, s):

###Q5a:

To speed up texting your friends, you are thinking of leaving out all vowels. Write a Python function shorten(s) that takes an arbitrary string and removes all uppercase and lowercase vowels.

def shorten(s):

###Q5b

You find out that the resulting words are sometime incomprehensible and like to improve your method by removing only those vowels that directly follow another letter. This means keeping the vowel at the beginning of a word–specifically, any letter following a space. Write a Python function shortenPlus(s)that takes an arbitrary string and removes some vowels.

def shortenPlus(s):

###Q6:

Given a dictionary that tells you a person’s major, write a Python function that, given a person’s name and a major, returns True if that person is majoring that subject, and Falseotherwise

def check_major(name, major, majors_dict):

###Q6b:

Given a dictonary that instead maps majors to lists of names, repeat the above question.

def check_major2(name, major, major_dictionary):

###Q7:

In computing, a checksum is a simple but effective way to verify transmitted data. Given a list of data and a checksum value, return true or false, based on whether the data matches the checksum value.

To compute the data from the checksum value, compute the sum of the list. Have your function output the value of the sum in binary. Next, compute the four least significant bits of the sum and print these in binary. Next return from the function whether or not these four bits match the checksum given as an argument.

This may be helpful… https://wiki.python.org/moin/BitwiseOperators

def checksum (array, checksumValue) :

###Q8:

Write a function that translates an English sentence to leetspeak.

Hints: You will want to turn your sentence into a list of words, replace those, and then turn it back into a sentence before replacing letters. To turn a list of words into a sentence, you can use the syntax:
new_sentence = " ".join(old_list)
This will join all the values in “old list” into a string, separated by spaces.
If you want to determine if a word is in your dictionary, use “if word in dictionary.keys()”

You may assume that the sentences are, much like YouTube comments, devoid of any punctuation or capitalization.

Use the following general algorithm: Replace the following words:

  • elite -> leet
  • the -> teh
  • hacker -> haxor
  • hack -> hax
  • own -> pwn
  • owned -> pwned
  • dude -> dood
  • rocks -> roxxorz
  • 1md3 -> most awesome course ever

If any word ends with an ‘s’, replace it with a ‘z’

Replace the following letters:

  • a -> “@”
  • e -> “3”
  • t -> “7”
  • l -> “1”
  • o -> “0”
  • s -> “$”

def leet(s):