Here is the solution to your problem. Note that I have to check if i
is odd, due to Python indexes starting from 0. For example, in Python, an index of 1 is the second position.
num = input("Enter a number: ")
return_num = ""
# Iterates through input
for i in range(len(num)):
# Checks if digit is at even position
if i % 2 == 1:
# If so, adds it to return_num
return_num += num[i] # + " " if you want spaces between numbers
print(return_num) # Prints 4690 with your input
Alternatively, you could achieve this using one for-loop. (Credit to OneCricketeer.)
num = input("Enter a number: ")
return_num = ""
# Iterates through specified indexes of input
for i in range(1, len(num), 2):
return_num += num[i] # + " " if you want spaces between numbers
print(return_num) # Prints 4690 with your input
Or, if you want to have the shortest program humanly possible to solve your problem (Credit to Tomerikoo):
num = input("Enter a number: ")
print(num[1::2]) # Prints 4690 with your input