Write a program that reads in a word entered by the user and checks whether: the word has at least 8 characters, starts with a vowel, has alternating vowels and consonants, and the consonants are in increasing alphabetical order.Note that you can check letters for alphabetical order using <.For example:a < bTruez < bFalseYour program should work for words entered upper or lower case, and must use a single functionis_alternating(word) that returns True if the word has the above pattern, and False otherwise.(Hint. Remember to write a loop that goes through each letter and check for the necessaryconditions. Using indexing is important here as you need to compare letters in different positions.We have looked at a similar piece of code in our first lecture!) Here is an example run of thisEnter a word = eLimiNateeLimiNateThe word eliminate is alternatingEnter a word = agenesesagenesesThe word ageneses is not alternatingEnter a word = ADAGEADAGEThe word adage is not alternatingThe word eliminate has this alternating pattern since we have that: l'<m'<n'<t.The word adage is not long enough, ageneses has two consonants that are identical and as a resultnot in strictly increasing alphabetical ordering.When you have tested your code, please submit it as hw4_part1.py.Part 2: LegosIn this part, we will work with legos. Suppose you are given a list of lego pieces that you own, butyou have a new project. You want to see if you have enough of a specific piece. Even if you do nothave the exact piece, you can put together different lego pieces to make up bigger pieces.11 21 22 21 22+ =21Figure 1: Left: all the possible lego pieces for this homework, name is dimension of the lego (no12, only 21). Right: example of combining two 21 pieces to make up a 22 piece.Write a program to read from a file the list of all lego pieces you currently have. Ask the userfor the type of lego piece and the number of such pieces that she is searching for. Then, returnwhether you can make that many pieces of legos by using the legos in your collection. You willonly consider methods in which one type of lego is used. For example, you can make up a 22 legousing: two 21 legos, or four 11 legos. Also, return the list of remaining legos after this request issatisfied.Here are some sample outputs of your program:Current legos [11, 11, 11, 11, 11, 11, 21, 21, 21, 21,22]Type of lego wanted = 2121Quantity wanted = 22I can use 2 21 legos for thisRemaining legos [11, 11, 11, 11, 11, 11, 21, 21, 22]Current legos [11, 11, 11, 11, 11, 11, 21, 21, 21, 21,22]Type of lego wanted = 2222Quantity wanted = 22I can use 4 21 legos for thisRemaining legos [11, 11, 11, 11, 11, 11, 22]Current legos [11, 11, 11, 11, 11, 11, 21, 21, 21, 21,22]Type of lego wanted = 2121Quantity wanted = 66I dont have 6 21 legosIn the first example, we have exact match. In the second case, we use substitution. In the thirdexample, we search for 6 21 legos or 12 11 legos. Given we do not have either one, we fail. Notethat a different solution exists to this last case using 4 21 and 4 11 legos. This is a much harderproblem (mix and match) and we will not allow it for simplicity.To solve this problem, you will first read from a file how many of each type of lego pieces youcurrently have, such as the one below:6 114 211 22using the function we provided you in hw4_util as follows:import hw4_utillegos = hw4_util.read_legos()print legosIf you execute this program with the above file, you will get the list below.[11, 11, 11, 11, 11, 11, 21, 21, 21, 21, 22]A very easy way to solve this problem is to use the count() function of lists. For example, giventhe above list, legos.count(11) returns 6. You need to write the if statements to check foreach lego, whether a substitute exists. You also need to use list functions to remove the found legosfrom the list of existing legos. Always try to using the biggest possible lego first.It should be obvious how you can put smaller pieces together to make up bigger pieces, but weprovide possible subtitutions here for completeness. We only use one type of lego for any request,no mix and match.Piece Possible replacement21 2 1122 2 214 11Note that we only gave you one test file. But, you must create other test files to make sure thatthe program works for all possible cases. Feel free to share your test files on Piazza and test cases.Discussing test cases on Piazza are a good way to understand the problem.We will test your code with different input files than the one we gave you in the submission server.So, be ready to be tested thoroughly!Ask us for suggestions on how to organize your code on Piazza, we will provide suggestions. Thisis a good homework to test how to input a function as an argument to a list and modify the list inthat function (for removal of legos). I also recommend you separate the search for substitutions ina different function, for a simpler program.When you have tested your code, please submit it as hw4_part2.py.Part 3: Google Flu TrendsHave you heard about Google Flu Trends? Researchers have shown that when the flu season starts,the Google queries on flu symptoms and treatments goes up significantly. So, we can look at Googlequeries to see what is happening in the world. In this homework, you will be using real Google flutrend data for 2014 for many different countries.Write a program to read in the flu trends for different countries for all of the 52 weeks in 2014.Print the trend in a single line. For each week in which the flu search was higher than usual, print aplus sign and otherwise print a minus sign. Also print a header for the months of the year, startingwith 1. Here is a possible run:First country = USUSSecond country = SwitzerlandSwitzerland1 2 3 4 5 6 7 8 9 10 11 12US -++++++++++++-Switzerland +++++The country name is printed as entered by the user left justified to 12 characters. Each month isprinted left justified 4 characters.To accomplish this, you will use another function from the utility module provided for this homework.Given a string containing a country name, it returns you a list of 52 numbers. Try thefollowing:import hw4_utilcdata = hw4_util.read_flu(Switzerland)print cdataYou will get the following list:[5, 6, 7, 12, 15, 18, 19, 12, 9, 9, 8, 6, 5, 6, 4, 5, 3, 3, 3, 3, 2,2, 2, 2, 2, 2, 2, 1, 2, 2, 1, 2, 2, 4, 4, 4, 3, 3, 4, 4, 4, 4, 4,5, 4, 4, 5, 5, 6, 6, 4, 7]You have 52 values corresponding to the flu based search frequency for each week. Apparently theSwiss really dont really search for flu online.Now, given a country such as this, you can find when flu is peaking for this country. It is when theflu volume is higher than or equal to the cutoff value which we will compute as:cutoff = (average value + max value)/2For the above country, cutoff would be 12 (average is 5 and max is 19, so the cutoff is 12 usinginteger division.)We only have five values higher than cutoff for the above list. We will now print a line for thiscountry by printing a minus sign when the value is below cutoff and a plus sign otherwise, as shownbelow:Switzerland +++++The function hw4_util.read_flu will return an empty list whenever the country cannot be found.Your program must give an error message for all missing countries as shown below.First country = KanadaKanadaSecond country = MeksikoMeksikoI could not find country KanadaI could not find country MeksikoFirst country = USUSSecond country = KanadaKanadaI could not find country KanadaWhen you have tested your code, please submit it as hw4_part3.py
CSCI1100
[Solved] CSCI1100 Homework 4 Loops and Lists Part
$25
File Name: CSCI1100_Homework_4_Loops_and_Lists_Part.zip
File Size: 376.8 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.