0

Shorter

How can be this be shorter "if x >40 and x <70:"? My emulator keeps telling me that this could be shorter

8th Jul 2018, 6:51 PM
I Am Arthur
I Am Arthur - avatar
6 Answers
+ 12
if 40 < x < 70: or if 70 > x > 40:
8th Jul 2018, 7:05 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 4
if x in range (41, 70):
8th Jul 2018, 7:02 PM
Sebastian Keßler
Sebastian Keßler - avatar
+ 4
It's cool, but honestly saying I don't like this notation, it looks a bit awkward :)
8th Jul 2018, 7:14 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 2
Maybe: 0 if x > 40 and x < 70 else 1 If that statement is true it'll return true and if false will return false.
8th Jul 2018, 7:08 PM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 2
Kuba SiekierzyƄski It's useful for short, repetitive conditional statements. I agree it shouldn't be used as a full-time replacement for if/else.
9th Jul 2018, 12:54 AM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 1
Kuba SiekierzyƄski Thanks...I think i im dumb for not think in this option haha
8th Jul 2018, 7:08 PM
I Am Arthur
I Am Arthur - avatar