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
Readme [11.4K]
3 years ago
8

Given positive integer n, write a for loop that outputs the even numbers from n down to 0. If n is odd, start with the next lowe

r even number. Hint: Use an if statement and the % operator to detect if n is odd, decrementing n if so. Enter an integer: 7 Sequence: 64 20 (2) If n is negative, output 0, Hint: Use an if statement to check if n is negative. If so, just set n = 0. Enter an integer: -1 Sequence: 0 Show transcribed image text (1) Given positive integer n, write a for loop that outputs the even numbers from n down to 0. If n is odd, start with the next lower even number. Hint: Use an if statement and the % operator to detect if n is odd, decrementing n if so. Enter an integer: 7 Sequence: 64 20 (2) If n is negative, output 0, Hint: Use an if statement to check if n is negative. If so, just set n = 0. Enter an integer: -1 Sequence: 0
Computers and Technology
1 answer:
seropon [69]3 years ago
7 0

Answer:

The program in Python is as follows:

n = int(input("Enter an integer: "))

if n < 0:

   n = 0

print("Sequence:",end=" ")

for i in range(n,-1,-1):

   if i%2 == 0:

       print(i,end = " ")

Explanation:

This gets input for n

n = int(input("Enter an integer: "))

This sets n to 0 if n is negative

<em>if n < 0:</em>

<em>    n = 0</em>

This prints the string "Sequence"

print("Sequence:",end=" ")

This iterates from n to 0

for i in range(n,-1,-1):

This check if current iteration value is even

   if i%2 == 0:

If yes, the number is printed

       print(i,end = " ")

You might be interested in
If you reformat the hard drive on a computer, it erases all personal information from your computer and makes it safe to donate.
melamori03 [73]
The answer would be false
8 0
4 years ago
What is the purpose of copyfitting?
stiv31 [10]

Answer:

ms word can help you to writer and print

ur document and make u more attractive

Explanation:

a

3 0
4 years ago
Why is it important to follow a consistent naming convention for variables?
Vitek1552 [10]

Answer:

today I am going to be out for the job interview so if I will make it happen I am going to New Orleans this week to get the kids to work on the spot and I can get ready to go out to dinner and I can make a few more people

4 0
3 years ago
What type of network does not have centralized control, such as one in a small office or home office?
ella [17]
The answer is P.2.P

:)
7 0
4 years ago
How does a computer work
ivann1987 [24]

Answer:

computer works on electricity

Explanation:

6 0
3 years ago
Other questions:
  • Which of the following best defines natural selection?
    8·1 answer
  • What stdio.h input function would be used to get input from the user by the keyboard? Write the code to obtain the voltage drop
    7·1 answer
  • Algorithmic Complexity: what is the asymptotic complexity (Big-O) of each code section? Identify the critical section of each.\
    8·1 answer
  • PLEASE HELP! 2D Animation!
    12·1 answer
  • Which type of styles can be applied to a word, phrase, or sentence?
    7·1 answer
  • In what way was the Ohio River Valley a factor in the French and Indian War? The Ohio River Valley was controlled by both France
    8·2 answers
  • Buying the newest phone as soon as it is released when your current phone works perfectly is not a good idea for all but which o
    10·2 answers
  • 1 cup coffee cream = ____ tbsp butter plus ____ c milk
    11·1 answer
  • When creating a storyboard, in which section do you mention how you move from one shot to the next?
    8·1 answer
  • What is the difference between a free-form outline and a modified outline?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!