i have string variables and for example two of them are empty "".
Those empty strings should be set to 0.
And after that, all string variables should be converted into an integer, to be able to do some checks on it and return them.
But my current problem is that my loop does not set the empty strings to 0.
I get the following output when i run the script:
['1000', '', '', '5']
Only Numbers!
And do you have an idea how i can work with the variables after the loops? Without the need of list index?
def func():
bandwidth = 2000
voice = "1000"
signal = ""
stream = ""
business = "5"
empty_check = [voice, signal, stream, business]
for n in empty_check:
if n == "":
n = 0
print(empty_check) # check if "" was set to 0
try:
for n in empty_check:
n = int(n)
except ValueError:
print("Only Numbers!")
else:
if (empty_check[0] > 2000000) or (empty_check[0] > bandwidth):
print("Error")
elif (empty_check[1] > 1000000):
print("Error")
elif (empty_check[2] + empty_check[3]) > 95:
print("Error")
else:
return bandwidth, empty_check[0], empty_check[1], empty_check[2], empty_check[3]
test = func()