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
Which measure should you take for the periodic maintenance of your computer?
WITCHER [35]
I believe the answer is annual maintenance
Hope this helps :p
6 0
3 years ago
Read 2 more answers
Consider an online shopping portal that allows a customer to browse and purchase different products. The products are arranged u
o-na [289]
Way too much to read bye
7 0
2 years ago
Read 2 more answers
Which of the following is not one of the four methods for classifying the various instances of malware by using the primary trai
BlackZzzverrR [31]

Answer: Source

Explanation: The malware is the software persisting malicious approach to cause the damage/loss.The primary trait of the malware are infection,concealment,etc.

The concealment refer to the malware such as the Trojan horse, and other viruses that has only purpose to cause the malfunctioning in the system.The virus that get into the other software and then damage the system in known as the infectious malware .

The circulation is the transferring of the virus in the circular manner between the system for the damaging.Thus,the only trait that is not the part of the malware is source.

4 0
3 years ago
How can people efficiently and effectively influence lots of people throughout the world
tatuchka [14]

Answer:

The word efficient denotes the ability to achieve a good goal toward a person, and effectiveness denotes reliable production or achievement.

Explanation:

Many people around the world can set efficient goals, that is, to influence or encourage other people to make good projects or changes in their lives, by example or simply teach them with patience and altruism.

In this way effectiveness will be seen, that is, the product or the achievement precisely when we observe how people undertake new projects in their lives

3 0
3 years ago
How to see how many words you have on google docs?
liberstina [14]
In the menu bar, click Tools > Word Count or hit Ctrl/Cmd + Shift + C.
4 0
3 years ago
Other questions:
  • What is the difference between a switch's physical interface and the vlan interface?
    10·2 answers
  • To type the letter address, _________ space from the dateline
    9·2 answers
  • What are the 7 basic components found in a computer tower
    5·2 answers
  • Alicia uses a software application to store the names, email addresses, and phone numbers of her friends in alphabetical order.
    15·2 answers
  • Write a program to convert a fraction to a decimal. Have your program ask for the numerator first, then the denominator. Make su
    10·1 answer
  • Write a Java program that generates a new string by concatenating the reversed substrings of even indexes and odd indexes separa
    5·1 answer
  • Attackers need a certain amount of information before launching their attack. One common place to find information is to go thro
    11·1 answer
  • What is the definition of posture<br>​
    7·1 answer
  • You are starting a small web hosting business and
    11·1 answer
  • Which component is most likely to allow physical and virtual machines to communicate with each other?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!