For this assignment, I am tasked to:
- Input a number
- Remove even digits from the given number without changing the order of the digits
For example: 123407 will print 137
If a number starts with 246 then it prints 0.
I am not allowed to use strings, lists, functions, packages, recursion, ..., only mathematical operations.
Here is my code so far:
POSITION = 1 # give the digit position of the number
OUTPUT = 0 # printing the output of the result
enterNum = int(input('Enter a Number')) # user inputs a number
while enterNum != 0:
digit = enterNum % 10 # last digit of the number if number is odd
enterNum = enterNum / 10 # shift decimal places and remove the digit position
if digit % 2 == 1:
OUTPUT += POSITION * digit # if digit is odd, add it to the position
else:
continue
print(OUTPUT)
I am quite lost on what to do. When the number is 123407, I can only go up to printing 7. I do not know how to store the number in the data type and combine the digits in the end to get 137. Furthermore, I have a hard time looping through the number. It just gives me 7.