Reading Time: 1 minutes
Tuple of Odd Numbers in Python: A Python program which accepts end bounds of a range from the user, and outputs a tuple containing only odd numbers lying in the range. For example, if the user inputs 10 & 20, then the output should by (11, 13, 15, 17, 19).
Tuple of Odd Numbers in Python
lowerBound = int(input("Please enter lower bound of range: ")) upperBound = int(input("Please enter upper bound of range: ")) listOfOddNumbers = list() for number in range(lowerBound, upperBound + 1): if number % 2 == 1: listOfOddNumbers.append(number) tupleOfOddNumbers = tuple(listOfOddNumbers) print(tupleOfOddNumbers)
Try it here.