Question

BlockPy: #33.8) Maximum Odd Use the Min/Max pattern to write a function maximum_odd that finds the highest odd value in the list (consumes a list of numbers and returns a number). Use the provided helper function is_odd (that consumes a single number and returns a boolean indicating whether it is true or false). Do not change the helper function is odd. Call your maximum_odd function on your favorite list of numbers Console Feedback: Instructor Feedback You cannot use the builtin function len (builtin_use) Blocks ++Split | / Text | .0 Reset 1 def is_ odd (a_number): 3 def maximum_old(a_list): Run O Upload History return a-number % 2 1 4 for i in range(len(1st)): if is_odd(1st[i]): if maxValue <1st[i]: maxValue lst[i] return maxValue 9 print (maximum_odd ([1,2,3,4,5]))
media%2F360%2F36029dff-1cbf-4a72-8c95-d0
media%2F6fe%2F6feada60-18db-4d27-bf3e-19
media%2F138%2F1385f7e4-5bcb-43e6-9b93-b0
0 0
Add a comment Improve this question Transcribed image text
Answer #1

33.8

# Python version : 2.7

# Python program to find the maximum odd number from a list of number

def is_odd(a_number):

               return a_number%2 == 1

              

def maximum_odd(a_list):

               max_odd = None

               for i in a_list:

                              if is_odd(i):

                                             if max_odd == None or (max_odd < i):

                                                            max_odd = i

               return max_odd

print(maximum_odd([1,2,3,4,5]))              

                             

#end of program

Code Screenshot:

1 2 # Python version : 2.7 3Python program to find the maximum odd number from a list of number def is odd (anumber) : 5 - return a number#2-1 8 두 def maximum-odd (a-list): max oddNone for i in a_list: 10 if is odd (i) 12 13 14 15 16 17 if Tax ¢)(id == None or (n.LK (x1:1 < ǐ.) : max odd = 1 return max_odd print (maximum odd([1,2,3,4,5]))

Output:

35.1

# Python version : 2.7

scores = "44,34,27,43,22,25"

total_score = 0

for a_score in scores.split(","):

               total_score = total_score + int(a_score)

print(total_score)            

#end of program

Code Screenshot:

Output:

35.3

# Python version : 2.7

# Python version to scan an input string and return the number of hot days minus number of cold days represented in the string

def add_hot_cold(observations):

               result=0

              

               for day in observations:

                              if day == 'H':

                                             result = result + 1

                              elif day == 'C':

                                             result = result - 1

                                            

               return result

              

print(add_hot_cold('HHHHHCCCHCHHHCHCHC'))

#end of program   

Code Screenshot:

Output:

35.4

# Python version : 2.7

# Python program to input a string of numbers separated by comma and calculate its sum

# input (if using Python version 3 user input instead of raw_input)

numbers = raw_input(' Enter the numbers(separated by comma) : ')

sum =0 # variable to store th sum

for number in numbers.split(','): # split the number on comma

               sum = sum + int(number) # calculate the sum by converting each number in string to int

              

print(sum)            # print the sum

#end of program

Code Screenshot:

Output:

  

Add a comment
Know the answer?
Add Answer to:
BlockPy: #33.8) Maximum Odd Use the Min/Max pattern to write a function maximum_odd that finds the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Saved BlockPy: #33.8) Maximum Odd Use the Min/Max pattern to write a function maximum_odd that finds...

    Saved BlockPy: #33.8) Maximum Odd Use the Min/Max pattern to write a function maximum_odd that finds the highest odd value in the list (consumes a list of numbers and returns a number). Use the provided helper function is_odd (that consumes a single number and returns a boolean indicating whether it is true or false). Do not change the helper function is_odd. Call your maximum_odd function on your favorite list of numbers. Server Execution: Idle Feedback: Ready Console Run "Blocks 艹Split...

  • Using PYTHON: (Find the index of the smallest element) Write a function that returns the index...

    Using PYTHON: (Find the index of the smallest element) Write a function that returns the index of the smallest element in a list of integers. If the number of such elements is greater than 1, return the smallest index. Use the following header: def indexOfSmallestElement(lst): Write a test program that prompts the user to enter a list of numbers, invokes this function to return the index of the smallest element, and displays the index. PLEASE USE LISTS!

  • 1. use python List to Dictionary Write a function that has three parameters: a list of...

    1. use python List to Dictionary Write a function that has three parameters: a list of unsorted numbers with no duplicates, a start number, and an end number. This function should return a dictionary with all integers between the start and end number (inclusive) as the keys and their respective indices in the list as the value. If the integer is not in the list, the corresponding value would be None. Example unsorted list: [2,1,10,0,4,3] two numbers: 3, 10 returned...

  • Question 1a - Increasing Numbers in List - First Occurence(3 points) Write a function numIncreasing1(L) that...

    Question 1a - Increasing Numbers in List - First Occurence(3 points) Write a function numIncreasing1(L) that takes as input a list of numbers and returns a list of the first sequence within that is increasing order, and has a length of at least 2. If no increasing sequential numbers are found, (ie. the input list is in descending order) then naturally a list of just the first value is returned. Increasing sequence means for a number to be valid it...

  • Write a function called most_consonants(words) that takes a list of strings called words and returns the...

    Write a function called most_consonants(words) that takes a list of strings called words and returns the string in the list with the most consonants (i.e., the most letters that are not vowels). You may assume that the strings only contain lowercase letters. For example: >>> most_consonants(['python', 'is', 'such', 'fun']) result: 'python' >>> most_consonants(['oooooooh', 'i', 'see', 'now']) result: 'now' The function that you write must use a helper function (either the num_vowels function from lecture, or a similar function that you...

  • Problem 20 [ 2 points ] Use the Design Recipe to write a function, print_histogram that...

    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 the FDR to design and write a function, maxValTimes, that takes a list of integers...

    Use the FDR to design and write a function, maxValTimes, that takes a list of integers and returns a set containing the value(s) that occur the same number of times as the maximum value in the list. If the list is empty, return an empty set.   For example if the list was [2,1,1,2,3,3,1] the function would return {2,3} as the maximum value is 3 which occurs twice, and 2 also occurs twice (but 1 occurs 3 times). For full marks,...

  • Python: Using your favorite text editor, write a program that outputs the string representation of numbers...

    Python: Using your favorite text editor, write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”. Submit by uploading a .py file Example: n = 15, Return: [ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"...

  • Write a recursive function called freq_of(letter, text) that finds the number of occurrences of a specified...

    Write a recursive function called freq_of(letter, text) that finds the number of occurrences of a specified letter in a string. This function has to be recursive; you may not use loops!   CodeRunner has been set to search for keywords in your answer that might indicate the use of loops, so please avoid them. For example: Test Result text = 'welcome' letter = 'e' result = freq_of(letter, text) print(f'{text} : {result} {letter}') welcome : 2 e and A list can be...

  • Make a public class called ManyExamples and in the class... Write a function named isEven which...

    Make a public class called ManyExamples and in the class... Write a function named isEven which takes in a single int parameter and returns a boolean. This function should return true if the given int parameter is an even number and false if the parameter is odd. Write a function named close10 which takes two int parameters and returns an int. This function should return whichever parameter value is nearest to the value 10. It should return 0 in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT