-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_0509_input.py
More file actions
66 lines (53 loc) · 1.42 KB
/
Copy pathpython_0509_input.py
File metadata and controls
66 lines (53 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
## input 함수 사용 예시
## 게임 아이디와 비번 입력하는 과정으로 만들어봄.
>>> user_name = input("아이디를 입력해주세요 : ")
아이디를 입력해주세요 : 나의본운동은
>>> print(user_name)
나의본운동은
>>> type(user_name)
<class 'str'>
>>> password = input("비밀번호를 입력해주세요 : ")
비밀번호를 입력해주세요 : 12345
>>> print(password)
12345
>>> type(password)
<class 'str'>
>>>
## 문자열을 숫자로 변환해야 숫자 연산에 활용가능.
## python은 문자열은 문자열끼리 연산, 숫자는 숫자끼리 연산해야함.
## password type을 str에서 int와 float로 바꾸는 과정
>>> type(password)
<class 'str'>
>>> password
'12345'
>>> password = int(password)
>>> password
12345
>>> type(password)
<class 'int'>
>>> password = float(password)
>>> password
12345.0
>>> type(password)
<class 'float'>
## 소수점이 있는 숫자 형식의 문자열을 int() 함수로 변환할때
## 오류가 난다.
>>> a = 55.5
>>> a
'55.5'
>>> type(a)
<class 'str'>
>>> a = int(a)
Traceback (most recent call last):
File "<pyshell#53>", line 1, in <module>
a = int(a)
ValueError: invalid literal for int() with base 10: '55.5'
## class를 str에서 float로 변환하고 다시 int로 하면 된다.
>>> a = float(a)
>>> a
55.5
>>> a = int(a)
>>> a
55
>>> type(a)
<class 'int'>