Python Program to Find Sum of Series 2+4+6+8

n = int(input("Enter the number: "))
previous_num=1
total=0
while(previous_num<=n):
total=total+previous_num
previous_num=previous_num*2
print("The sum of series is: %s"%(total))

Output:

Python Program to Find Sum of Series 2+4+6+8