Encoding error


#1

i do coding like this :

def power(base, exponent):
result = base**exponent
print "%d 의 %d 제곱은 %d 입니다." % (base, exponent, result)
power(37,4)

but error message received like this
'UnicodeDecodeError: 'cp949' codec can't decode bytes in position 3-4: illegal multibyte sequence'

so i search to google .. i know how to solve this problem
they talk to me.. add the next line
like this..
sys import
reload(sys)
sysdefaultencoding('cp949')

so i add !! but error message received again like this..
unknownerror : 37**4 is 1874161 Result none in interpreter.
and Oops, try again, The result is not accurate.

what the problem?
help me


#2

Be sure to return the result after printing so the SCT can see it.


#3

Hi @objectrunner56314 ,

@mtf has pointed out an important problem with your power function. Unless you correct that problem, the submission correctness test (SCT) will not pass your code.

There are additional problems.

Try this modification of your code in a Python 2.x interpreter outside the Codecademy environment, where it will execute without an error ...

# -*- coding: utf-8 -*-

def power(base, exponent):
    return base ** exponent

base = 37
exponent = 4
result = power(37, 4)
print "%d 의 %d 제곱은 %d 입니다." % (base, exponent, result)

Output ...

37 의 4 제곱은 1874161 입니다.

The code, however, will still not work in Codecademy, because the encoding specifier in the first line will cause a malfunction in Codecademy's SCT.


#4

but how to solve it?

So it is no way to proceed to the next chapter?


#5

Tell us more detail please


#6

sys import
reload(sys)
sysdefaultencoding('cp949')

unknownerror : 37**4 is 1874161 Result none in interpreter.
and Oops, try again, The result is not accurate.

Assuming there is no exception raised in the following, the missing return statement may be the only problem. Try it again, with return. What happens?

def power(base, exponent):
    result = base**exponent
    print "%d 의 %d 제곱은 %d 입니다." % (base, exponent, result)
    return result

power(37,4)

If it still doesn't work, then switch from Korean to English.


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.