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
PLEASE HELP :(
belka [17]

Taking data and instructions from a user, processing the data as per instructions, and displaying or storing the processed data, are the four major functions of a computer. These functions are also known as the input function, process function, output function, and storage function, respectively.

5 0
3 years ago
How do i work this out? does anyone do programming?
Pavlova-9 [17]
Answer : No sorry ..
6 0
3 years ago
What is communication​
IgorLugansk [536]

Answer:

it is when u talk to someone

6 0
4 years ago
Read 2 more answers
Which of the following describes the function of a web browser?
Papessa [141]

Answer:

option D.

Explanation:

A web browser is a software program that allows a user to locate, access, and display web pages. Browsers are used primarily for displaying and accessing websites on the internet, as well as other content created using languages such as Hypertext Markup Language (HTML) and Extensible Markup Language (XML).

it acts like an interface between a user and a world wide web

8 0
3 years ago
Read 2 more answers
Explain how using assistive technology can promote healthy emotional and social development. Discuss how you think young childre
mina [271]
Assistive technology is commonly used by people with multiple disabilities. It helps them to live more comfortable and it makes their life much easier.
7 0
4 years ago
Other questions:
  • Create a java class for Bank Accounts with these public String attributes: ownerName, acctNbr and these private double attribute
    11·1 answer
  • What did Francis Ford Coppola and George Lucas create?
    10·1 answer
  • The overall visual look of a chart in terms of its graphic effects, colors, and backgrounds is the:
    5·1 answer
  • Use the Date object and the Array object to determine and diplay information about the current date on your webpage. Your output
    11·1 answer
  • Digital on a smart phone means the camera is actually zooming in on the photo itself not the subject that you are shooting true
    8·1 answer
  • Who invented Leibnitz calculating machine ?
    12·1 answer
  • What is the best scenerio for
    11·2 answers
  • Which programming languages is best for game development? ​
    10·1 answer
  • 3 ᴍᴜʟᴛɪᴘʟᴇ-ᴄʜᴏɪᴄᴇ Qᴜᴇꜱᴛɪᴏɴꜱ
    8·1 answer
  • Who is your favorite person from squid game?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!