Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Program to convert digits in a list into an integer
- thislist = [3,4,5,6,7,1,4]
- print(thislist)
- length = len(thislist) # length of the list to iterate in the while loop below
- print ("length of list : ", length)
- i = 0 #temp variables for looping and calculation
- j = length - 1
- k = 0
- total = 0
- # Loop to calculate place value of digits
- while i < length:
- k = thislist[i] * (10 ** (j)) # Extract each digit and multiply by place value
- i = i + 1 # Increment loop counter
- j = j - 1 # Decrement place value
- total = total + k # Add intermediate result to total
- print ("The answer is: ", total)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement