HI guys im new in python<3
i Write this code to read text from .docx file and put the numbers in to a list to calculate their sum
now i need to covert list to a Variable and calcute sum of them !
My code:
<code>from docx import Document
num_list = []
doc = Document('File.docx')
for para in doc.paragraphs:
for char in para.text:
if char in '0123456789۰۱۲۳۴۵۶۷۸۹.':
num_list.append(char)
else :
if num_list != [] and num_list != ['.'] :
print(num_list)
num_list = []
</code>
<code>from docx import Document
num_list = []
doc = Document('File.docx')
for para in doc.paragraphs:
for char in para.text:
if char in '0123456789۰۱۲۳۴۵۶۷۸۹.':
num_list.append(char)
else :
if num_list != [] and num_list != ['.'] :
print(num_list)
num_list = []
</code>
from docx import Document
num_list = []
doc = Document('File.docx')
for para in doc.paragraphs:
for char in para.text:
if char in '0123456789۰۱۲۳۴۵۶۷۸۹.':
num_list.append(char)
else :
if num_list != [] and num_list != ['.'] :
print(num_list)
num_list = []
Output :
<code>['2', '.', '7']
['۳']
['۳', '۰', '۶']
['۷', '۴']
['۵']
['۹', '۰']
['۱', '۰']
['۱', '۵']
['۲', '۶']
</code>
<code>['2', '.', '7']
['۳']
['۳', '۰', '۶']
['۷', '۴']
['۵']
['۹', '۰']
['۱', '۰']
['۱', '۵']
['۲', '۶']
</code>
['2', '.', '7']
['۳']
['۳', '۰', '۶']
['۷', '۴']
['۵']
['۹', '۰']
['۱', '۰']
['۱', '۵']
['۲', '۶']
what i want :
convert list to flout Variable and calcute sum
<code>['2', '.', '7'] --> 2.7
</code>
<code>['2', '.', '7'] --> 2.7
</code>
['2', '.', '7'] --> 2.7
New contributor
Arian Alijani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.