This is what I have right now, the if statements feels like doesn’t engaged in the code. I have also tried random.randint() but didn’t work
async def open_huge_cat_case(ctx):
huge_case = randint(1, 100)
if huge_case == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40):
await ctx.send('1')
if huge_case == (41, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65):
await ctx.send('2')
if huge_case == (66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85):
await ctx.send('3')
if huge_case == (86, 87, 88, 89, 90, 91, 92, 93, 94, 95):
await ctx.send('4')
else:
await ctx.send('5')
>Solution :
You can’t compare using == for a list (or tuple) of things, instead you need in like so:
async def open_huge_cat_case(ctx):
huge_case = randint(1, 100)
if huge_case in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40):
await ctx.send('1')
elif huge_case in (41, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65):
await ctx.send('2')
elif huge_case in (66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85):
await ctx.send('3')
elif huge_case in (86, 87, 88, 89, 90, 91, 92, 93, 94, 95):
await ctx.send('4')
else:
await ctx.send('5')
You also need elif as shown above to make sure only one executes at a time.
It would also be better to use range() like so:
huge_case = randint(1, 100)
if huge_case in range(1, 41):
await ctx.send('1')
elif huge_case in range(41, 66)):
await ctx.send('2')
elif huge_case in range(66, 86):
await ctx.send('3')
elif huge_case in range(86, 96):
await ctx.send('4')
else:
await ctx.send('5')
This makes it clearer and easier to write.