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]
3 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:
Volgvan3 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
what should the timing of transition slides be per minute? maintain the flow of the presentation to ______ slides per minute.
murzikaleks [220]

Answer:

1-2

Explanation:

It depends on the amount of information that you have on each slide. You want to make sure you're not going too fast but also make sure you arent taking up to much time. Be sure to speak clearly it will make the presentation better by looking clean and time organized. hope this helps :)

8 0
3 years ago
A block style business letter is:
julia-pushkina [17]

the answer is A typewritten form of communication with all parts aligned to the left margin

3 0
4 years ago
Computer virus is a<br> a. software<br> b. hardware<br> c. bacteria<br> d. none of these
Nimfa-mama [501]
The answer is software
8 0
4 years ago
One of the benefits of conditional ____________________ is that it helps you analyze data by highlighting significant trends in
Lelu [443]

Answer is Formatting

When conditional formatting is applied to your data, you can quickly and easily identify variances in different values within a quick glance. This makes worksheets easier to comprehend. With conditional formatting, you are able to apply formatting such as icons, data bars, and colors.

 

 

 






5 0
4 years ago
Is USA TestPrep a test-taking site that won't let you access other windows without kicking you off?
olga_2 [115]

Answer:

usatestprep literally just does what the name says; it prepares you for tests in america. it doesn't kick you off if you access other windows

Explanation:

3 0
4 years ago
Other questions:
  • When a field is declared static there will be ________. Group of answer choices two reference copies of the field for each metho
    14·1 answer
  • Your computer has gradually slowed down. What's the most likely reason?
    8·1 answer
  • Stacey wants to change her document to landscape view instead of portrait. Jesse wants to change the scale of his document. Whic
    5·1 answer
  • If someone receives a shock, or a piece of equipment is throwing sparks or arcing you should try to pull them away from the sour
    7·1 answer
  • Which of the four basic functions of a computer refers to the collection of data by a computer?
    11·2 answers
  • Assuming that a user enters 5 as the age, what is the output of the following code snippet? int age = 0; Scanner in = new Scanne
    10·1 answer
  • How many bytes are there in 256 Kbytes?
    6·1 answer
  • A class can inherit behavior from a parent but also define its own and override parent behavior. This is called:
    8·1 answer
  • Read the following statements and select the
    5·2 answers
  • A group of small local businesses have joined together to share access to a cloud-based payment system. Which type of cloud is m
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!