In Python use the function design recipe from Chapter 3 of Practical Programming to develop a function named first_last6. The function takes a list of integers. (Assume that the list will not be empty.) The function returns True if a 6 is the first element or the last element or if both the first and last element are 6. Otherwise, the function returns False.
The solution to the above question is given below with screenshot of output.
=====================================================
I kept the logic simple and i have tested all outputs.
If there is anything else do let me know in comments.
=====================================================
============ CODE TO COPY ===============================
def first_last6(num_list):
""" Returns True if a 6 is the first element or
the last element or
if both the first and last element are 6.
Otherwise, the function returns False. """
if ( num_list[0] == 6 and num_list[-1] == 6 ) or num_list[0] == 6 or num_list[-1] == 6:
return True
return False
mylist1 = [6,2,3,4,5]
mylist2 = [1,2,3,4,5,6]
mylist3 = [1,2,3,4,5]
mylist4 = [6,2,3,4,6]
print(first_last6(mylist1))
print(first_last6(mylist2))
print(first_last6(mylist3))
print(first_last6(mylist4))
=====================================================
output :


In Python use the function design recipe from Chapter 3 of Practical Programming to develop a...
use the function design recipe from chapter 3 of practical programming to develop a function named sum_x. the function takes a set of n points: { (x0 , y0 ), (x1 , y1 ), … (xn-1 , yn-1 ) }. each point is represented by a tuple containing two floats. the first and second floats are the point's x and y coordinates, respectively. the function returns the sum of all the x coordinates: x0 + x1 + x2 + …...
Exercise 4 Step 1: Create a new editor window and save it as a file named lab9ex4.py. Step 2: Use the function design recipe to develop a function named common_end. The function takes two lists of integers that are not empty, but which may have different lengths. The function returns True if they have the same first element or the same last element or if the first and last elements of both lists are the same. Otherwise, the function returns...
Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...
PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a function yesOrNo which has no parameters. When called, it gets input from the user until the user types either 'yes' or 'no', at which point the function should return True if the user typed 'yes' and False if the user typed 'no'. Any other entries by the user are ignored and another value must be input. For example: Test Input Result print(yesOrNo()) hello blank...
Python Use the Design Recipe to write a function called running_average that repeatedly asks the user to input integers at the keyboard until they type the word done. Return the average of the values they entered. You may assume the user will only enter integers or "done". Include a docstring!
Problem 20 [ 2 points ] Use the Design Recipe to write a function, print_histogram that consumes a list of numbers and prints a histogram graph using asterisks to represent each number in the list. Use one output line per number in the list. You may assume that only integers are passed to this function. Your function should ignore negative values. Include a docstring! Test Result print_histogram([ 0, 2, 4, 1]) ** **** * print_histogram([10, 5, 3, -1, 8]) **********...
Use Python
[12] 10. Complete the code for the function documented below. Note that the function gets all its input from the parameters and not from the keyboard. It returns all information to the calling function and not to the computer display def frstiggest la, b, c) 'Assume a, b, and c are integers. Return True if a is greater than both b and c, Examples anh False otherwise would be True; firstigges (9, 6, 7) and firstBiagest (4, -2,...
Problem 1. Write a Python function times_i_at_odd(L) that takes as arguments a list L and returns a list consisting of the elements of L multiplied by the index number of the element at odd positions. (Use list comprehensions) >>> times_i_at_odd([1,2,3,4,5,6,7,8,9,10]) [2, 12, 30, 56, 90] Problem 2. Write a recursive function sum_cols(grid, n) that takes a list of lists of integers grid and integer n and returns the sum of column n in grid. For example, the call sum_cols([[1,2,3,4], [10,20,30,40],...
1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...
Python Programming Assignment: Write a function to take a string S that returns True if the letters are in ascending order and False otherwise. To do this go over each letter and check that it is less than the letter that precedes it. Then write a function main that gets one input from the user, then if passing that input to the function above returns True, then show "String is in order", otherwise show " String is unordered".