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]
2 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]2 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
Is the address 7b invalid regarding cell references?
Lubov Fominskaja [6]

Answer:

It is not valid

Explanation:

I'll assume the question relates to cell referencing in Microsoft Excel.

To reference a cell in Excel, we make use of the following steps:

  • Write out the cell column name first
  • Followed by the row number

7b implies that, the row number first, followed by the column name; this doesn't follow the naming convention of cells.

Hence, 7b is invalid.

3 0
3 years ago
The power relationship on a transformer states that O Power in = power out + loss O Power in = 1/2 power out (Power in = 2 x pow
lions [1.4K]

Answer:

D

Explanation:

5 0
3 years ago
You decide to buy some stocks for a certain price and then sell them at anotherprice. Write a program that determines whether or
Otrada [13]

Answer:

no_of_shares = int(input("Enter the number of shares: "))

purchase_price = float(input("Enter the purchase price of the stock: "))

sale_price = float(input("Enter the sale price of the stock: "))

total_stock_price = purchase_price*no_of_shares

total_spend_on_buying = total_stock_price + (0.03*total_stock_price)

total_sale_price = sale_price*no_of_shares

commission_while_selling = total_sale_price*0.03

net_gain_or_loss = total_sale_price - (total_spend_on_buying + commission_while_selling)

if(net_gain_or_loss<0):

print("After the transaction, you lost {} dollars".format(abs(net_gain_or_loss)))

else:

print("After the transaction, you made {} dollars".format(abs(net_gain_or_loss)))

7 0
3 years ago
If you have a list consisting of just numbers, then you can add all of the values in the list using the sum() function.
Vlada [557]

Answer:

See explaination

Explanation:

def sum_lengths(value_list):

total = 0

for x in value_list:

if (type(x)==int) or (type(x)==float):

total += x

return total

6 0
3 years ago
Describe how to deploy a website and make it as secure as possible while reducing its resources used
erastova [34]

Answer:

Explanation:

in order to deploy a website, you use these 5 steps, the first step is the preparation step, the second step is to set up DNS record, in step 3 a live testing is set up, in step 4 you set up email accounts while in step 5, you back up and now go live.

in order to secure your website from any threat, malware it hacker it it is necessary to use HTTPS. HTTPS, protects the websites integrity. it also provides data protection as data encryption provides such security. parameterized queries can also be used.

5 0
3 years ago
Other questions:
  • Im trying to learn c# for unity does anyone know any good sources
    10·1 answer
  • If the physical memory size is doubled without changing any of its other parameters, the number of entries in the page table
    5·1 answer
  • Taken together, the physical and data link layers are called the ____________________. Internet layer Hardware layer Internetwor
    15·1 answer
  • When you print ____, the presentation is printed with one or more slides on each piece of paper?
    11·1 answer
  • What task does the casting director do, apart from auditioning actors?
    8·1 answer
  • Which of the following statements about email is true?
    5·1 answer
  • What are the 2 things you are not sure about evaluating functions​
    7·2 answers
  • Evolucion de los sistemas operativos
    5·1 answer
  • What are the trinity of the computer system
    15·1 answer
  • Which of the following tools might the security administrator use to perform further security assessment of this issue?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!