Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Page 229 P4.1 Write programs with loops that compute a. The sum of all ev

ID: 3881133 • Letter: P

Question

Python Page 229 P4.1 Write programs with loops that compute
a. The sum of all even numbers between 2 and 100 (inclusive).
b. The sum of all squares between 1 and 100 (inclusive).
c. All powers of 2 from 20 up to 220.
d. The sum of all odd numbers between a and b (inclusive), where a and b are inputs.
e. The sum of all odd digits of an input. (For example, if the input is 32677, the sum would be 3 + 7 + 7 = 17.)
Python Page 229 P4.1 Write programs with loops that compute
a. The sum of all even numbers between 2 and 100 (inclusive).
b. The sum of all squares between 1 and 100 (inclusive).
c. All powers of 2 from 20 up to 220.
d. The sum of all odd numbers between a and b (inclusive), where a and b are inputs.
e. The sum of all odd digits of an input. (For example, if the input is 32677, the sum would be 3 + 7 + 7 = 17.)
Page 229 P4.1 Write programs with loops that compute
a. The sum of all even numbers between 2 and 100 (inclusive).
b. The sum of all squares between 1 and 100 (inclusive).
c. All powers of 2 from 20 up to 220.
d. The sum of all odd numbers between a and b (inclusive), where a and b are inputs.
e. The sum of all odd digits of an input. (For example, if the input is 32677, the sum would be 3 + 7 + 7 = 17.) Page 229 P4.1 Write programs with loops that compute
a. The sum of all even numbers between 2 and 100 (inclusive).
b. The sum of all squares between 1 and 100 (inclusive).
c. All powers of 2 from 20 up to 220.
d. The sum of all odd numbers between a and b (inclusive), where a and b are inputs.
e. The sum of all odd digits of an input. (For example, if the input is 32677, the sum would be 3 + 7 + 7 = 17.)

Explanation / Answer

The code is

"""
cards={"A":"Ace","2":"Two","3":"Three","4":"Four","5":"Five","6":"Six","7":"Seven","8":"Eight","9":"Nine","10":"Ten","J":"Jack","Q":"Queen","K":"King"}
suit={"S":"Spade","C":"Clubs","D":"Diamond","H":"Hearts"}

s=input()
print(cards[s[0]]+" of "+suit[s[1]])
"""
#part a
sum=0
for i in range(2,101):
if i%2==0 :
sum=sum+i
print("Sum of even numbers between 2 and 100 is "+str(sum))
#part b
sum=0
for i in range(1,101):
sum=sum+i*i
print("Sum of squares between 1 and 100 is "+str(sum))

#part c

l=[]

for i in range(2,221):
l.append(2**i)
#list l will contain powers of 2

#part d
a=int(input())
b=int(input())
sum=0
for i in range(a,b+1):
if i%2!=0:
sum=sum+i
print("The sum is "+str(sum))


#part e

a=input()
sum=0
for i in a:
if int(i)%2!=0:
sum=sum+int(i)
print("The sum is "+str(sum))

The output is

Sum of even numbers between 2 and 100 is 2550
Sum of squares between 1 and 100 is 338350
10
20
The sum is 75
32677
The sum is 17

Do give a thumbs up as it matters a lot