how to write error
Could somebody please point out where my ValueError syntax is wrong? Thank you!
def GeneratingList(n,k):
try:
l = []
while (n <=k):
for i in range(n):
v.append(QQ(randint(1,k)))
if (len(set(l)) == len(l)):
return l
else:
l = []
assert false
except ValueError:
print("value error, enter valid input n >= k")
In the line
v.append(...)
, I think you should replacev
byl
.You don't need
try: ... except: ...
in this code. Simply replaceassert false
with yourprint(...)
statement.In general never use
l
for a variable, well one letter variables are in general not really welcome, but this "ell" is even worse, it looks like a one... You may also better try something likeand then arrange somehow that the list has different elements, if this is needed...