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
abruzzese [7]
3 years ago
12

a. displays the sum of all even numbers between 2 and 100 (inclusive). b. displays the sum of all squares between 1 and 100 (inc

lusive). c. displays the powers of 2 from 1 up to 256. d. displays the sum of all odd numbers between a and b (inclusive), where a and b are inputs. e. displays the sum of all odd digits of an input. (For example, if the input is 32677, the sum would be 3 + 7 + 7 = 17.) You must achieve each step using a loop.
Computers and Technology
1 answer:
LuckyWell [14K]3 years ago
4 0

Answer:

The program required is in the explanation segment.

Explanation:

Program :

import math

# a. displays the sum of all even numbers between 2 and 100 (inclusive).

print("All even numbers from 2 to 100 inclusive ")

sum=0

i=2

while i<=100:

if i %2 ==0:

sum=sum+i

print(i,end=" ")

i=i+1

print("\nThe sum of all even numbers between 2 and 100 (inclusive) :",sum);

#b. displays the sum of all squares between 1 and 100 (inclusive).

print("\nAll squares numbers from 1 to 100 inclusive:")

i=1

sum=0

while i<=100:

print(i*i,end=" ")

i=i+1

sum=sum+(i*i)

print("\n\nThe sum of all squares between 1 and 100 (inclusive) is :",sum)

#c. displays the powers of 2 from 1 up to 256.

print("\nAll powers of 2 from 2 ** 0 to 2 ** 8:")

i=0

while True:

p=math.pow(2,i)

if p>256:

break

print("2 ** ",i," is ",int(p))

i=i+1

#d. displays the sum of all odd numbers between a and b (inclusive), where a and b are inputs

print("\nCompute the sum of all odd integers between two intgers ")

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

b=int(input("Enter another integer: "))

count = 0

temp=a

sum=0

while a<=b:

if a%2!=0:

print(a,end=" ")

sum=sum+a

a=a+1

print("\nThe total of the odd numbers from ", temp ," to ", b ,"is",sum)

#e.displays the sum of all odd digits of an input. (For example, if the input is 32677, the sum would be 3 + 7 + 7 = 17.)

print("\nCompute the sum of the odd digits in an integer ")

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

count=0

sum=0

temp=n

while n!=0:

rem = n%10

if rem%2!=0:

sum=sum+rem

count=count+1

n=int(n/10)

print("Sum of the odd digits is ",sum)

print("The total of the odd digits in ",temp," is ",count)

You might be interested in
Consider the class ScopeTest defined this way:
Tasya [4]

Answer:

im working on this too but i think this is d

Explanation:

7 0
3 years ago
Which two statements are true about algorithms?
DENIUS [597]

Answer:

I. Algorithms can be written using pseudocode.

II. Algorithms can be visualized using flowcharts.

Explanation:

An algorithm can be defined as a standard formula or procedures which comprises of set of finite steps or instructions for solving a problem on a computer. The time complexity is a measure of the amount of time required by an algorithm to run till its completion of the task with respect to the length of the input.

The two statements which are true about algorithms are;

I. Algorithms can be written using pseudocode. A pseudocode refers to the description of the steps contained in an algorithm using a plain or natural language.

II. Algorithms can be visualized using flowcharts. A flowchart can be defined as a graphical representation of an algorithm for a process or workflow.

Basically, a flowchart make use of standard symbols such as arrows, rectangle, diamond and an oval to graphically represent the steps associated with a system, process or workflow sequentially i.e from the beginning (start) to the end (finish).

3 0
3 years ago
Read 2 more answers
What are issues to consider when deciding to build software in-house or purchase commercial off-the-shelf software (cots)?
Scrat [10]
<span>On the computer there are always issues. For a developer to sit all day in front of a google that always invents things and the flashy images that disrupt everything. Googling on facebook is also an issue. Youtube, everything that contain flashy image is quite disruptive. If you think about content, maybe googling is less inventive. In a way it's nicer to buy applications but if you finally think of building it, there are always nicer ways of spending time. I prefer to go to seaside when I can.</span>
7 0
3 years ago
A complete traversal of an n node binary tree is a(n)____ "operation if visiting a node is O(1)for the iterative implementation
ch4aika [34]

Answer:

B.O(n).

Explanation:

Since the time complexity of visiting a node is O(1) in iterative implementation.So the time complexity of visiting every single node in binary tree is O(n).We can use level order traversal of a binary tree using a queue.Which can visit every node in O(n) time.Level order traversal do it in a single loop without doing any extra traversal.

8 0
3 years ago
This rlly isnt a question but give me some movies to watch or netflix movies/shows to watch
katovenus [111]
White chicks is a good one
5 0
2 years ago
Read 2 more answers
Other questions:
  • Which of the following should you avoid when designing your Print resume?
    11·1 answer
  • In addition to training on the products and on company policy, it does not make sense to be prepared to speak about your company
    6·2 answers
  • A patient presents at an outpatient urgent care facility with an acute illness and is seen by a provider. A detailed history wit
    13·1 answer
  • What are the features of Cobol language that make it suitable for programming business applications.
    6·1 answer
  • What is Celeste? ( This is for my coding class )
    6·2 answers
  • What term is used to describe our connection with eachother through technology
    6·1 answer
  • Explain how the organ systems work together to warm up the body on a cold day
    12·2 answers
  • Language modeling incorporates rules of __. Select all that apply.
    7·1 answer
  • Which of these are examples of an access control system? Check all that apply.
    7·1 answer
  • Internal exception java.net.socketexception connection reset 1.18
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!