When I run the bash program that calls the python script below I get this error: line 12, in roundup return int(int(math.ceil(x / 1000)) * (10**3)) TypeError: unsupported operand type(s) for /: 'str' and 'int'
When the python script is run by itself there are no issues or errors. I checked to make sure that the bash variable was not a float and it is not on both programs. I am not sure how to fix this. I tried int(int(math.ceil(x / 1000)) * (10****3)) and int(math.ceil(x / 1000)) * (10**3)
import math
import os
pdiv=os.environ["div"]
print(pdiv)
#pdiv=931573 in both the bash srcipt that is calling this python script and the python script
divi=str(pdiv)
divide=len(divi)
if divide >= 4 and divide < 7:
def roundup(x):
return int(int(math.ceil(x / 1000)) * (10**3))
z=roundup(pdiv)
array = [int(x) for x in str(z)]
if z == 4:
byte=str(array[0]) +'k'
elif z == 5:
byte=str(array[0]) + str(array[1]) + 'k'
elif divide == 6:
byte=str(array[0]) + str(array[1]) + str(array[2]) + 'k'
elif divide >= 7 and divide < 10:
def roundup(x):
return int(int(math.ceil(x / 1000000)) * (10**6))
z=roundup(pdiv)
array = [int(x) for x in str(z)]
if divide == 7:
byte=str(array[0]) +'m'
elif divide == 8:
#byte=print(array[0], end="");print(array[1], end="");print('m')
byte=str(array[0]) + str(array[1]) + 'm'
elif divide == 9:
byte=str(array[0]) + str(array[1]) + str(array[2]) + 'm'
file = open("Bytes.txt", "w")
file.write(byte)
file.close
os.environ[...]are always strings. Convertpdivtointorfloat.ifblocks, define them globally. If you need different denominators and exponents, make them function parameters.