알고리즘/코드워
[python]How do I compare numbers?
(ㅇㅅㅎ)
2020. 4. 16. 21:30
728x90
반응형
https://www.codewars.com/kata/55d8618adfda93c89600012e/train/python
Codewars: Train your coding skills
Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential.
www.codewars.com
더보기

내 코드
is를 ==으로 바꿔주면 됩니다.
is는 변수가 같은 객체(Object)를 가리키면 True이지만 ==는 변수가 같은 값(Value)을 가지면 True이다.
what_is함수에 42 * 42의 값을 넣으면 식이 들어가는 것이 아니라 계산된 값이 들어가기 때문에 is 대신 ==을 사용해야 합니다.
# My Code
def what_is(x):
print(x)
if x == 42:
return 'everything'
elif x == 42 * 42:
return 'everything squared'
else:
return 'nothing'
if __name__=='__main__':
answer = what_is(0)
print(answer)
answer = what_is(123)
print(answer)
answer = what_is(-1)
print(answer)
answer = what_is(42)
print(answer)
answer = what_is(42 * 42)
print(answer)
|

반응형