Write a program that lets user enter a integer number N: a. Calculate the sum of all…
- User
Write a program that lets user enter a integer number N:
a. Calculate the sum of all digits of N
b. Calculate the sum:
S(n) = 1 + 1/3 + 1/5 + ... + 1/(2N + 1)
- Assistant
Here is a python program that fulfills the given requirements:
pythondef sum_of_digits(n): sum = 0 while n > 0: digit = n % 10 sum += digit n = n // 10 return sum def sum_series(n): sum = 0 for i in range(1, 2*n+2, 2): sum += 1/i return sum # Get the integer number N from the user N = int(input("Enter an integer number N: ")) # Calculate and print the sum of digits of N sum_digits = sum_of_digits(N) print("Sum of digits of {} is: {}".format(N, sum_digits)) # Calculate and print the sum of series sum_series = sum_series(N) print("Sum of the series is: {}".format(sum_series))