Final answer:
To compute the sum of various sequences, you can use loops and conditional statements in Python.
Step-by-step explanation:
To compute the sum of all even numbers between 2 and 100 (inclusive), you can use a loop to iterate through all even numbers within this range and add them up. Here's an example:
sum_even = 0
for num in range(2, 101, 2):
sum_even += num
print(sum_even)
To compute the sum of all squares between 1 and 100 (inclusive), you can use a similar loop to iterate through all numbers within this range and add their squares to the sum. Here's an example:
sum_squares = 0
for num in range(1, 101):
sum_squares += num ** 2
print(sum_squares)
To compute the sum of all odd numbers between a and b (inclusive), you can modify the range function accordingly. Here's an example:
a = 10
b = 20
sum_odd = 0
for num in range(a, b+1):
if num % 2 == 1:
sum_odd += num
print(sum_odd)
To compute the sum of all odd digits of a number n, you can convert it to a string first and then iterate through each digit. If the digit is odd, add it to the sum. Here's an example:
n = 32677
sum_odd_digits = 0
for digit in str(n):
if int(digit) % 2 == 1:
sum_odd_digits += int(digit)
print(sum_odd_digits)