chriswelborn 63

The odd numbers in your example are 2 and 4. So 6 is correct.
The even number in your example is 3. So 3 is correct.
I would've probably did something like this:

def findproductandsum(userinput):
    # Initialize counters.
    finalproduct, finalsum = 1, 0

    # Iterate over index and character in userinput.
    for i, digitchar in enumerate(userinput):
        # Convert digit character to integer
        digit = int(digitchar)
        # Position is i + 1 since the index is zero-based.
        if (i + 1) % 2 == 0:
            # Even.
            finalproduct *= digit
        else:
            # Odd.
            finalsum += digit
    return finalproduct, finalsum

# Use 'raw_input' on Python 2 though, it's a good habit to get into.
n = input('Enter a number: ')

# findproductandsum returns a tuple, so unpack it into p and s.
p, s = findproductandsum(n)
print('n: {}, product: {}, sum: {}'.format(n, p, s))

You can check it using only evens (product):

 assert(findproductandsum('01010101') == (1, 0))

and only odds (sum):

 assert(findproductandsum('10101010') == (0, 4))
Jai_4 commented: i havnt done so much of python yet. cant we do it without defining a function. also my teacher tells me that the first digit is 0th digit then so on so in 234:2 and 4 are even 3 is odd so sum is 3 and product 8. please write down a simpler code. +0

chriswelborn 63 ...

Grabs the location and name of the script file itself.