Language: PYTHON
Function name : favorite_day
Parameters : list of tuples (dates), int (weekday, 0-6, Mondays are
0),
int (day of the month 1 to 28)
Returns: dates: list of tuples
Description: Imagine that you have a favorite weekday, and want to
see if certain days fall on that weekday. Using the calendar module
from the Python standard library , write a function which takes in
a list of tuples formatted like [(month, year), etc.], your
favorite weekday, and a day of the month. Using the module, find
the weekday of each (month,year) tuple at the day of the month that
was passed in (1-28). If that weekday is equal to your favorite
weekday, add the tuple to a list to be returned at the end of your
code. Assume the day of the week will lie within 0-6 inclusive and
the day of the month will be always be valid.
(Hint: look at calendar.weekday method)
Test Cases:
>>> dates = [(1, 1999), (7, 1980), (3, 2018), (12,
2003)] >>> print(favorite_day(dates, 6, 20))
[(7, 1980)]
>>> dates = [(10, 1803), (1, 2019), (6, 1964), (11,
1920), (2, 2011)] >>> print(favorite_day(dates, 0,
1))
[(6, 1964), (11, 1920)]
#look for the indentation
CODE:
import calendar
def favorite_day(dates, week_day, day):
match_weekday = []
# looing on the list
# i, j have the values in months, years
for i, j in dates:
#calendar.weekday(year,
month)
if calendar.weekday(j,
i, day) == week_day:
match_weekday.append((i, j))
# return the list
return match_weekday
dates = [(10, 1803), (1, 2019), (6, 1964), (11, 1920), (2,
2011)]
print(favorite_day(dates, 0, 1))
# dates = [(1, 1999), (7, 1980), (3, 2018), (12, 2003)]
# print(favorite_day(dates, 6, 20))
# [(7, 1980)]
Language: PYTHON Function name : favorite_day Parameters : list of tuples (dates), int (weekday, 0-6, Mondays...
python Days of the Week Function Name: days_of_the_week() Parameters: list of birthdays ( list ), year (int ) Returns: list of names ( list ) Description: You and your friends all want to celebrate your birthdays together, but you don't want to stay up late on a school night. Write a function that takes in a list of tuples formatted as (day ( int ), month ( int ), name (string)), and a year ( int ). Use Python's calendar...
Language: Python Topic: Tuples Function name : todo_tuple Parameters : todo (list of tuples of strings), completed (list of strings) Returns: final_list (list) Description : Write a function that takes in a list of tuples of strings that represents the work you have to do in each class, and a list of strings that represent the work you have already completed. Each tuple in the todo list represents the work for a single class. For this function, go through the...
Language: Python Topic: API and JSON Function name: min_pop_countries Parameters: region (str), num (int) Return: list of tuples Description: You are working on a project for your Demography class and you are tasked with finding the top num most populous countries in a given region . Instead of looking up on the Internet, you decide to apply your CS1301 knowledge of APIs and write a function to solve the problem for you. Develop a function that takes in a region...
Language: Python Topic: Try/Except Function name : add_divide Parameters : list of ints, int Returns: float Description: Given a list of integers and a number, you want to add the numbers in the list to a total value by iterating through the given list. However, when the index you are at is divisible by the integer passed in, you must instead divide the current total by the element at that index. You must be careful when dividing the total (you...
Language: Python Function name : findwaldo Parameters : string Returns: int Description: Write a recursive function that takes in a string containing some combination of letters, numbers, and spaces, and return the starting index of the first instance of “waldo” contained in that string. If the string does not contain “waldo”, return -1. This function IS case sensitive, so “waldo” is not the same as “WALDO”. Code using string functions such as .index() and .find() that oversimplify the problem will...
Language: Python Topic: Dictionaries Function name: catch_flight Parameters: dictionary, tuple containing two strings Returns: dictionary Description: You’ve been stuck in NYC for around 8 months all by yourself because you haven’t been able to find a good time to fly home. You’re willing to go to any city but want to see how many flights to each location fit your budget. You’re given a dictionary that has city names (strings) as the keys and a list of prices (list) and...
IN PYTHON 3 LANGUAGE, please help with function, USE RECURSION ONLY def im(l: 'an int, str,list,tuple,set,or dict') -> 'an int, str, tuple, or frozenset' pass SAMPLE OUTPUT: The following call (with many mutable data structures) imm(1) returns 1 imm('a') returns 'a' imm( (1, 2, 3)) returns (1, 2, 3) imm( frozenset([1, 2, 3])) returns frozenset({1, 2, 3}) imm( [1, 2, 3, 4, 5, 6]) returns (1, 2, 3, 4, 5, 6) imm( [1, 2, [3, [4], 5], 6]) ...
Python String Product Function Name: string Multiply Parameters: sentence (str), num (int) Returns: product (int) Description: You're texting your friend when you notice that they replace many letters with numbers. Out of curiosity, you want to find the product of the numbers. Write a function that takes in a string sentence and an int num, and find the product of only the first num numbers in the sentence. If num is 0, return 0. If num > O but there...
Write a program that, given a month and year, prints a calendar, such as June 2016 Su Mo Tu We Th Fr Sa 5 6 7 8 910 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 To find out the weekday of the first day of the month, call this function: Computes the weekday of a given date. @param year the year @param month the month (1=January 12=...
In Python. #1. please write a function called "stocksell", #2. the input parameters are the price list (l) and the ith day,i from [0, 7], #3. the return value is the jth day you should sell to make the most profit, #4. print the profit #for example a = stocksell(l, 2) then a = 6 #(2nd day price is 32, selling day is 6th day, price is 35) l = [34,47,32, 28, 29, 31, 35,34]