Answer the question
In order to leave comments, you need to log in
How to convert the resulting variable into a numeric one?
Good afternoon. Sorry I'm new.
I use a variable in the code (it reads the number of files in the directory), then I need to convert this variable into a numeric one, so that I can use it further for mathematical operations: example:
import os
def fcount(path):
#Counts the number of files in a directory - коли
count = 0
for f in os.listdir(path):
if os.path.isfile(os.path.join(path, f)):
count += 1
return count
a = r"C:\Python"
# a переменная которую надо конвертировать
c = float( input('Введите от фасованное количество продукта! ') )
d = a / c
print( str(d))
Answer the question
In order to leave comments, you need to log in
Where exactly is this?
it reads the number of files in a directory
a = r"C:\Python"
The above code should work, in theory. Please provide an example of the input that causes the error and the full text of the error.
Based on the conversion to float, I can only assume that you are entering a number with a decimal point ("2.3") and not a decimal point ("2.3").
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question