'Try Except Python, functions doesnt get read?
i am a beginner with python and i have the following problem.I want to create a code that takes 3 inputs separated by comma but at the same time these inputs must be int,str,int/float .I have created a function(check) that returns True if those creteria are met.nevertheless it seems that when i insert this line inside the 'try' ,nothing happens.So i can get a answer 10 for the name.
while True:
try:
aa, name, note = [x for x in input("insert the following aa,name,note :\n").split(',')]
check(aa,name,note )==True
except:
print("Please insert the data with the following format : aa,name,note")
continue
else:
break
Solution 1:[1]
as been said earlier this is not a great practice to just leave except blank. also you can just use because you're using bool function, but if you really want to use exceptions you can try this;
while True:
try:
aa, name, note = [x for x in input("insert the following aa,name,note :\n").split(',')]
assert(check(aa,name,note)) # assert will throw exception if argument is False
except:
print("Please insert the data with the following format : aa,name,note")
continue
else:
break
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ????? ??????? |
