asked 31.5k views
3 votes
Write code that generates a random odd integer (not divisible by 2) between 50 and 99 inclusive.

asked
User Mhabiger
by
7.9k points

1 Answer

2 votes

import random

nums = [x for x in range(50,100) if x%2!=0]

print(random.choice(nums))

We use a list comprehension to create a list of the odd numbers between 50 and 99. Then we randomly choose one of those numbers using the random module.

answered
User Shakib Ahmed
by
8.1k points

No related questions found