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]
4 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]4 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
Your laptop normally connects to your home wireless network automatically, but recently you have to connect to the network manua
finlep [7]
Your software is not remembering your password or SSID , maybe your router also has a forget all setting
8 0
3 years ago
How many months have 28 days?
Reika [66]

Answer:

All months of the year have at least 28 days, while February is the only month that is comprised of only 28 days (except for leap years)

5 0
3 years ago
Glven an array named Scores with 25 elements, what is the correct way to assign the 25th element to myScore? A. myScores + 25 B.
Marat540 [252]

Answer:

myScore Scores[24]

Explanation:

The array is used to store the data in continuous memory location.

The index of array start from zero, it means first element store in the index zero and second element store in the index 1. So, the index at which the element store is less than 1 from the number of element.

so, the last element is 25 - 1=24.

Option A: myScores + 25

It is not the correct way to store the element.

Option B: myScore Scores[24]

it is the correct form and also the index location is correct.

Option C: myScore Scores[25)

index number is wrong and also the bracket is wrong, it must be [ ].

Option D: myScore== Score[last]

It is not the correct way to store the element.

There, the correct option is B.

6 0
3 years ago
PLEASE HURRY!!<br> Look at the image below
Tanzania [10]

Answer:

source append (6,2)

Explanation:

Mark me as brain list

7 0
3 years ago
Regardless of if you use social media or not, would you rather be conservative rather than outgoing on social media? Why or Why
Alla [95]

Answer: I imagine conservative is the correct answer.

Explanation: However it's not the answer I agree with. As long as you stay anonymous online, there's no punishment to being outgoing.

4 0
3 years ago
Other questions:
  • Type the correct answer in the box.
    7·1 answer
  • Grace is the sub-editor in a business firm. which feature of a word processing program would she use to make her changes visible
    14·1 answer
  • Chances are if you ar Chances are, if you are involved in a crash, it will happen __________ a. during a long trip. b. close to
    7·2 answers
  • Consider the situation you addressed in the previous question. Create numeric cost estimates for each of the costs you listed. C
    10·1 answer
  • Write a Java program that can compute the interest on the next monthly mortgage payment. The program reads the balance and the a
    12·1 answer
  • People who score high on the Big Five trait dimension of ________ tend to use more adjectives in their e-mail communications. Gr
    15·1 answer
  • How much heat is needed to raise the temperature of 7g of water by 15oC?
    6·1 answer
  • Lester has to create an app that can support offline data and rich media content such as audio and video. In which programming l
    15·1 answer
  • Quiz Time!
    14·1 answer
  • after landing, you are tying down the aircraft when a person approaches and asks: "faa. are you the pilot of this aircraft?" wha
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!