Question

Submit a single file named hw0.py that contains the solutions to the problems below. When you...

Submit a single file named hw0.py that contains the solutions to the problems below. When you are finished, test your solutions using the doctest: copy the file hw0TEST.py from d2l into your working folder. include the following code at the bottom of the module hw0.py, and then run your module.   Fix all failures before you submit your solutions.

if __name__=='__main__':

    import doctest

    print( doctest.testfile( 'hw0TEST.py'))

  1. Write a function moreOdds that accepts one argument, a list of integers.   The function then returns a bool that indicates whether the list contains(strictly) more odd numbers than even numbers.   Sample output:

    >>> moreOdds( [2,3,4,5,7] )

True

>>> moreOdds( [2,3,4] )

False

>>> moreOdds( [2,3,4,5] )

False

>>> moreOdds( [2,2,5,5] )

False

USE PYTHON 3.7

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def moreOdds(lst):
    evenCount = 0
    oddCount = 0
    for x in lst:
        if(x%2==1):
            oddCount += 1
        else:
            evenCount += 1
    if(oddCount > evenCount):
        return True
    else:
        return False

# Testing
print(moreOdds( [2,3,4,5,7]))
print(moreOdds( [2,3,4]))
print(moreOdds( [2,3,4,5]))
print(moreOdds( [2,2,5,5]))

Add a comment
Know the answer?
Add Answer to:
Submit a single file named hw0.py that contains the solutions to the problems below. When you...
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
  • PROBLEM 3 Rewrite Program 2. This is you must use keyword arguments to pass number of kWh and customer type to the bill_calculator function when it is called. Save your Python program in a file named Lab07P3.py. Submit the file to Blackboard for cred

    Problem 3  Rewrite Program 2.  This is you must use keyword arguments to pass number of kWh and customer type to the bill_calculator function when it is called. Save your Python program in a file named Lab07P3.py.  Submit the file to Blackboard for credit.This is what i wrote for prgram 2:():     kwh = (())     cus = (())     cus.upper()     bill_calculator(kwhcus) (kwhcus):     kwh <= cus == :         price = kwh * kwh > cus == :         price = * + ((kwh - ) * )     kwh <= cus == :         price = kwh * kwh > cus == :         price = * + ((kwh - ) * )     (.format(price))

  • Assignment 6: Recursion Learning Outcomes • Learn how to craft solutions using recursion instead of loops....

    Assignment 6: Recursion Learning Outcomes • Learn how to craft solutions using recursion instead of loops. Instructions This assignment will be different than previous assignments (and most assignments which come after it). In this assignment, you will be crafting four solutions to four different problems. This assignment will also have special requirements regarding how you may code. You are not allowed to use assignment statements. This includes using preincement, postincrement, predecrement, and postdecrement. You are allowed to use assignment to...

  • # DISCUSSION SECTION WORK: # # 1. STUDENTS: download this file, ds4.py, and wordsMany.txt, from #...

    # DISCUSSION SECTION WORK: # # 1. STUDENTS: download this file, ds4.py, and wordsMany.txt, from # http://www.cs.uiowa.edu/~cremer/courses/cs1210/etc/ds4/ # Save both in the same folder. # # 2. TA (aloud) and STUDENTS: Read the comments from START HERE! (just after these instructions) # to definition of anagramInfo function. Discuss any questions about what the functions should do. # # 3. TA demonstrate running anagramInfo("wordsMany.txt") on this unchanged file, to # see that it behaves reasonably despite having incomplete anagram-testing functions. #...

  • Put all of your SQL code in a file named grades.sql and submit it below. Download...

    Put all of your SQL code in a file named grades.sql and submit it below. Download the starter code, which contains import_grades.sql and the grades.csv file. Using he import_grades, sql file, create your database and table. - 0 eded. 1 T Une Modify the LOAD DATA INFILE to correct the path to load the grades.csv file, and add/remove LOCAL he only modification you may make to the import_grades.sql or the grades.csv files. The data represents grades for assignments in a...

  • For written problems or problems where you are asked to provide an explaination you can submit...

    For written problems or problems where you are asked to provide an explaination you can submit your answers in a separate text file or you can just include them within your programs using Python comments. For problems requiring other written components (ie. structure chart), provide a pdf scan of the page(s). For each problem that requires coding, you must: Write a Python program Test, debug, and execute the Python program Save your program in a .py file and submit your...

  • PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything...

    PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...

  • Roadmap To start, use the provided template file (on Blackboard): project_01_template.py. Replace the pass statements with...

    Roadmap To start, use the provided template file (on Blackboard): project_01_template.py. Replace the pass statements with your code. Notice that we included test cases under every function. If you run the project_01_template.py file at this point it should print False for each test. After you write the correct code for each function, and then run the file, it should print True for each test. 1. Write a function named gc_content that takes one argument sed and performs the following tasks:...

  • in Python Project 5: Payroll (Part 1) CS 1410 Background In this project you will implement...

    in Python Project 5: Payroll (Part 1) CS 1410 Background In this project you will implement a simple payroll system. For the first part of the assignment, you will submit a UML class diagram. The hypothetical company we are considering has 3 classifications of employees: 1. Hourly 2. Salaried 3. Commissioned There are 24 pay periods per year; 1/24th of a salary is paid each pay period to employees who receive a salary. We won't worry about taxes and other...

  • Can you please write the two C++ modules below is a step by step instuctions to...

    Can you please write the two C++ modules below is a step by step instuctions to follow that will make it very easy thanks. Create a module called pqueue.cpp that implements priority queues, with a header file calledpqueue.hthat describes what pqueue.cpp exports. The interface includes the following, and nothing else. Types ItemType and PriorityType are discussed below under the refinement plan. A type, PriorityQueue. Creating a PriorityQueue object with line PriorityQueue q; makes q be an initially empty priority queue....

  • Can you please write the two C++ modules below is a step by step instuctions to follow that will ...

    Can you please write the two C++ modules below is a step by step instuctions to follow that will make it very easy thanks. Create a module called pqueue.cpp that implements priority queues, with a header file calledpqueue.hthat describes what pqueue.cpp exports. The interface includes the following, and nothing else. Types ItemType and PriorityType are discussed below under the refinement plan. A type, PriorityQueue. Creating a PriorityQueue object with line PriorityQueue q; makes q be an initially empty priority queue....

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