본문 바로가기
IT/프로그래밍

파이썬으로 메일 보내기, 기본 문법 - 내 일을 바꾸는 업무 자동화 3장

by nutrient 2021. 5. 29.
728x90
728x170

 

 

3.1-1

if True:
  print("less than 10")
    print("okay")

 

3.1-2

num = 10

if num < 10:
    print("less than 10")
elif num > 10:
    print("more than 10")
else:
    print("same")

if num < 10:
    print("less than 10")
if num < 15:
    print("less than 15")
if num < 20:
    print("less than 20")

 

3.1-3

data = 0

if data:
    print(data)
else:
    print("no data is available")

data = ['student', 'teacher']

if data:
    print(data)
else:
    print("no data is available")

 

3.1-4

user = {'name' : 'alghost', 'email' : 'alghost.lee@gmail.com', 'age' : 19}

if user.has_key('email'):
    if '@' not in user['email']:
        print('Wrong email')
    else:
        print('Email: ' + user['email'])
else:
    print('No email')

student = []
if user.has_key('age'):
    if user['age'] < 20:
        if user['name'] not in student:
            print('Name: ' + user['name'])
            student.append(user['name'])
    else:
        print('Not student')
else:
    print('No age')

if not student:
    print('No students')
else:
    print(student)

 

3.2-1

for count in [1,2,3,4,5]:
    print(count)

 

3.2-2

emails = ['example@gmail.com', 'example@naver.com']
for email in emails:
    print(email)

 

3.2-3

num = 0
for c in range(100):
    num = num + 1
print(num)

 

3.2-3_dict

student = {'name' : 'example', 'email': 'example@gmail.com'}

for k in student.keys():
    print(k + ': ' + student[k])

 

3.3-1

user_input = ''
while user_input != 'quit':
    user_input = input('Input: ')
    print(user_input)

 

3.4-1

user_input = ''
while user_input != 'quit':
    user_input = input('Input: ')
    print(user_input)

    if user_input == 'exit':
        break

 

3.4-2

emails = ['example1@gmail.com', 'example2@gmail.com', 'wrongemail3', 'example4@gmail.com']

for email in emails:
    if '@' not in email:
        continue
    print(email)

 

 

728x90
그리드형

댓글