Question: in python please help Exercise 4 Many aspects in our life consists of states that are repeated in a sequence and form cycles. For example,

in python please help
 in python please help Exercise 4 Many aspects in our life
consists of states that are repeated in a sequence and form cycles.
For example, traffic lights are green, then orange then red, then green

Exercise 4 Many aspects in our life consists of states that are repeated in a sequence and form cycles. For example, traffic lights are green, then orange then red, then green again and so on... Write a function that takes as input a list of elements, a starting element, and the number of next states. The function should make sure that starting element belongs to the list, then it should display the next states in the cycle. To test your code, use the below main program: print("first test") traffichights=["green", "orange", "red"] cycle(traffichights, "green", 2 ) print("second test") cycle(traffichights, "orange", 5 ) print ("third test") hours=[1, 2,3,4,5,6,7,8,9,10,11,12] cycle(hours 10,5) print("fourth test") cycle(hours, 12,0) You should then be able to get the following sample run: first test We start from green Then comes orange Then comes red second test We start from orange Then comes red Then comes green Then comes orange Then comes red Then comes green third test We start from 10 Then comes 11 Then comes 12 Then comes 1 Then comes 2 Then comes 3 fourth test We start from 12 Part II Exercise 5 Expanding on exercise 3, create a function makeUnique which has one parameter 1 istElements and returns a new list which has only the unique elements of 1 stElements. Don't forget to add an appropriate docstring. To test your function try the below assert statements (copy paste them to your code in the main function). assert (makeUnique([1,2, 3]) =[1,2,3]) assert (makeUnique ([])==[] ) assert (makeunique([' a ', b,c,b])==[a,b,c] ) assert (makeunique ([1,2,3,3])==[1,2,3]) assert (makeunique ([1,2,3,1])=[1,2,3,1]) print("All tests succesfull!") Exercise 6 Write a mode function that has a numbers parameter. numbers is a list of numbers. This function returns the numbers which appears the most frequently in the list, and how many times they appear. If two (or more) numbers appears with the same frequency, they should all be displayed. Passing an empty list to mode should cause it to return an empty list and frequency of 0 . Don't forget to add an appropriate docstring. To test your function try the below assert statements (copy paste them to your code in the main function). assert mode ([])=([],), "Empty list test failed!" assert mode ([1,2,3])=([1,2,3],1), "Test 2 failed. assert mode ([3,7,10,4,1,9,5,6,2,3]) w ([3],2), "Test 3 falled." assert mode ([3,7,10,4,1,4,2,2,8])==([4,2],2), "Test 4 failed." assert mode ([ a,b,b,c,a])=([a,b],2), "Test 5 failed." import random random. seed (42) testData =[3,7,10,4,1,9,6,4,4] for i in range (10e0): random. shuffle(testData) assert mode(testData) =([4],3) print("All tests succesful1!") Exercise 8 in exercise 2 you handled automatically orders from a shop with very limited number of choices. This approach would not scale for a supermarket or even a restaurant with a decent menu. Assume you have a list of all possible choices and another list with the corresponding prices. Write a program that asks the user which item he would like to purchase, then the quantity repeatedly. Once the customer has finished his order he enters done for the item, then the program summarizes the order and display the total bill. You need to validate the input as well. By using the lists: MENU_ITEMS [' "soup", 'salad', "humnus", "fattoush', "tabbouleh", "musakhan', "naqluba", "mansaf", "kibbeh", "kebab", "mandi', "biryand", "pizza", 'burger", "frles", "kunefe', "cheesecacke", "brownie"] PRICE_LIST =[12,15,16,13,17,32,28,46,52,45,34,25,19,22,12,15, 23, 21] You can get the following sample run: What would you 11ke to order? wings Sorry we do not have wings What would you like to order? pasta Sorry we do not have pasta What would you like to order? humnus How many humus do you want? done Please enter valid quantity. How many humus do you want? two Please entef valid quantity. How many humus do you want? 5 Please enter valid quantity. How many humus do you want? 2 What would you like to order? kibbeh How many kibbeh do you want? 5 What would you like to order? done Your order is: - 2 hunmus - 5 kibbeh Your total bil1 is 28e QAR

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!