Answer:
see explaination
Step-by-step explanation:
target_sum=float(input("Enter a target sum > 0 and <1 : ")) #asking user to enter the sum
while (target_sum<0 or target_sum>1): #if target sum not in range print the message
print("The target sum is not between 0 and 1")
target_sum=float(input("Please Enter a target sum > 0 and <1 : "))
computed_sum=0.00 #declare computed_sum
term_count=0 #declare term count and initalize to 0
r=1 #variable used to create the difference value
while computed_sum<target_sum: #iterate loop till computed sum is less than target sum
computed_sum=computed_sum+(1/(2**r)) #add previous computed sum with current term (1/2,1/4,1/8 etc)
term_count+=1 #increment term count
r+=1 #increment r value
print("Final Sum = " ,computed_sum) #finally print term count and final sum
print("Number of Terms= " ,term_count)