본문 바로가기
Python/Web Scraping

[Python] #1.9 Code Challenge! (#코딩공부)

by 함께 공부해요 2020. 2. 7.

https://youtu.be/I_e2Wn3LtBw


<복습>

https://wook-2124.tistory.com/17

 

[Python] #1.8 Keyworded Arguments (#코딩공부)

https://youtu.be/Z27sK7sNoSk #1.7 💖은 니꼬쌤의 말씀! I just wanted to say: Thank you for being here and watching our lectures. See you on the next video! <복습> https://wook-2124.tistory.com/15 [Py..

wook-2124.tistory.com


<준비물>

https://repl.it/

 

The world's leading online coding platform

Powerful and simple online compiler, IDE, interpreter, and REPL. Code, compile, and run code in 50+ programming languages: Clojure, Haskell, Kotlin (beta), QBasic, Forth, LOLCODE, BrainF, Emoticon, Bloop, Unlambda, JavaScript, CoffeeScript, Scheme, APL, Lu

repl.it

https://docs.python.org/3/library/

 

The Python Standard Library — Python 3.8.1 documentation

The Python Standard Library While The Python Language Reference describes the exact syntax and semantics of the Python language, this library reference manual describes the standard library that is distributed with Python. It also describes some of the opt

docs.python.org


1. 내가 만든 계산식 코드 plus, minus, times, division, remainder, negation, power

return int(lalala ← 아무거나 적음!)로 str이 오더라도 int(integer, 정수)로 변환할 수 있게 함수 설정을 한 뒤, plus(더하기), minus(빼기), times(곱하기), division(나누기), remainder(나머지), negation(= -a), power(제곱)을 return해줬다.

 

그 다음 a와 b를 Keyworded Argument 배웠던 내용대로 지정하고 result 값을 print해서

13, 7, 30, 3.3333333333333335(중간에 반올림 한건가.... 덜덜), 1, -10, 1000 값이 나왔다!


2-1. int(integer) 함수 순서바꿔보기

이걸 밑으로 빼고 그 위에 Keyworded Argument를 놓으면 "10", "3" str으로 써져있는건 어떻게 될까?!


2-2. str이어서 읽히지 않음, 그리고 밑에있는 코드는 의미가 없음

오른쪽 터미널에 unsupported operand type(s)라고 나오면서 실행되지 않는다. 그리고 그 밑에 retrun int 값은 읽히지도 않고 이미 위쪽 코딩에서 오류가 난 것을 알 수 있다.


2-3. str이 아니라 int를 a, b로 지정해주면?

a와 b를 str(문자열)가 아니라 int(정수)로 입력하면 밑에 return int(lalala)와 상관없이 위에 있는 코드만으로 실행이 잘 되는 것을 알 수 있다. 그러나 그러면 a와 b에는 정수 외에 다른 문자열이 들어간 수가 입력된다면, 가령 "10"과 "3"이 들어가면 오류가 날 수 있음을 알 수 있다.


3. 그러므로 처음 만든 코드식이 가장 안정적이라고 생각함!

그러므로 맨 앞에 a와 b 인자의 값으로 str이 오더라도 int로 변환해주는 함수식을 넣어줌으로써 오류를 하나 더 방지한 코드를 만들었다.


4. 니꼬의 답변!!💖

코딩의 '코'자도 모르는 나에게는 정말 은인같은 존재!!ㅎㅎ :)


※ 신종 코로나 바이러스 조심하세요!!!!

댓글