+ 2

Help me print a random number from a given range, and if it has a certain digit eg 5, then it shouldn't print it. Here's my work

Import random a = random.randint(1, 100) x = 5 if x = a: del x print (a)

10th Mar 2020, 10:03 PM
Walter
Walter - avatar
2 Answers
+ 4
a = str(random.randint(1, 100)) if not ("5" in a): print("Number has no 5s")
10th Mar 2020, 10:37 PM
👑 Prometheus 🇾🇬
👑 Prometheus 🇾🇬 - avatar
+ 1
a = random.randint(1, 100) x = a if str(5) not in str(a) else None If x: print(x) The condition is never met if x = none (I.e it has digit 5)
10th Mar 2020, 10:46 PM
Ali Abdelhady
Ali Abdelhady - avatar