Advertisement
TheGrimSoul

task1

Dec 22nd, 2024 (edited)
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. # Program to convert digits in a list into an integer
  2.  
  3. thislist = [3,4,5,6,7,1,4]
  4.  
  5. print(thislist)
  6. length = len(thislist) # length of the list to iterate in the while loop below
  7.  
  8. print ("length of list : ", length)
  9.  
  10. i = 0                   #temp variables for looping and calculation
  11. j = length - 1
  12. k = 0
  13. total = 0
  14.  
  15. # Loop to calculate place value of digits
  16. while i < length:
  17.     k = thislist[i] * (10 ** (j))    # Extract each digit and multiply by place value
  18.     i = i + 1                       # Increment loop counter
  19.     j = j - 1                         # Decrement place value
  20.     total = total + k             # Add intermediate result to total
  21.  
  22. print ("The answer is: ", total)
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement