1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
natima [27]
2 years ago
5

Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither.

The input begins with
Computers and Technology
1 answer:
Volgvan2 years ago
4 0

Question:

Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain less than 20 integers.

Answer:

Written in Python

listlent = int(input("Length of List: "))

mylist = []

mylist.append(listlent)

for i in range(listlent):

    num = int(input(": "))

    mylist.append(num)

<em>    </em>

evens = 0

odds = 0

for i in range(1,listlent+1):

    if mylist[i]%2==0:

         evens=evens+1

    else:

         odds=odds+1

       

if(evens == 0 and odds != 0):

    print("All Odds")

elif(evens != 0 and odds == 0):

    print("All Even")

else:

    print("Neither")

Explanation:

This prompts user for length of the list

listlent = int(input("Length of List: "))

This initializes an empty list

mylist = []

The following iteration reads the list items from the user

<em>mylist.append(listlent)</em>

<em>for i in range(listlent):</em>

<em>     num = int(input(": "))</em>

<em>     mylist.append(num)</em>

   

The next two lines initialize even and odd to 0, respectively

<em>evens = 0</em>

<em>odds = 0</em>

<em />

The following iteration if a list item is even or odd

<em>for i in range(1,listlent+1):</em>

<em>     if mylist[i]%2==0:</em>

<em>          evens=evens+1</em>

<em>     else:</em>

<em>          odds=odds+1</em>

This checks and prints if all list items is odd        

<em>if(evens == 0 and odds != 0):</em>

<em>     print("All Odds")</em>

This checks and prints if all list items is even        

<em>elif(evens != 0 and odds == 0):</em>

<em>     print("All Even")</em>

This checks and prints if all list items is neither even nor odd

<em>else:</em>

<em>     print("Neither")</em>

You might be interested in
Round Robin Algorithm
Reil [10]

Answer:

Please check the attachment.

Explanation:

avg turnaround time = (38+7+42+33+18)/5= 27.6

avg waiting timee = (33+5+28+23+17)/5= 21.2

And its D, A C in Gantt chart at last and exit time are 33, 38 and 42 mentioned as last three in Gantt chart.

7 0
2 years ago
Write a single instruction that inverts bits 5 and 6 in the bl register
katrin [286]

The single instruction that can inverts bits 5 and 6 in the bl register is xor bl,1100000b.

<h3>What is single instruction?</h3>

Single Instruction is a term that connote all the data streams are said to be processed though the use of the same compute logic.

Note that in the case above, the single instruction that can inverts bits 5 and 6 in the bl register is xor bl,1100000b.

Learn more about bits from

brainly.com/question/19667078

#SPJ12

5 0
2 years ago
Can you shoot video on the Olympus E-410?
Masja [62]
Yes you must update or do something first but then you can
6 0
3 years ago
Read 2 more answers
What are some elements commonly included in forms in Word? Check all that apply.
MArishka [77]

Answer:

dates

text

drop-down lists

8 0
3 years ago
This semester we looked at three languages (C++, Java and Python). One common rule in all three class checklists (for C++, Java
Marysya12 [62]

Answer:

The languages C++, Java, Python are Object Oriented Programming languages. What this means is that we create classes and then instantiate those classes. In C++ and Java, we use the new operator to instantiate the classes. So, if we want to display some data when we try to print the instance just like we print the variables of data types like int, double, string etc, we need to define what we need to display. It is because, class are just like data types like int, double etc. But as they are defined by the developer according to his/her needs, so the developer has to define what to print when they are printed.

5 0
3 years ago
Other questions:
  • Which of the following is true about REST?
    12·1 answer
  • You want to place a video from the internet to your desktop. what process do you use?
    15·1 answer
  • A factory producing cables for personal computers finds that its current average
    10·1 answer
  • Eight houses represented as cells are arranged in a straight line java int state []
    14·1 answer
  • Using PowerPoint or Impressed guarantees that your presentation will do which of the following?
    6·1 answer
  • There are _______ bits to every byte.
    14·2 answers
  • Setting the isShowing property to false of the opacity property to o will delete an object from an Alice world.
    15·2 answers
  • Yuygiihjiujjhuuuuykjyt​
    13·1 answer
  • Mississippi law codes state that bullying and cyberbullying are against the law. A court can decide to incur ___________________
    10·1 answer
  • The ______ Works on a single variable or constant. *​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!