I'm Electronic Engineer :)

[Do it] 점프 투 파이썬 - 3장 연습문제 code 본문

Study code & programming/Python

[Do it] 점프 투 파이썬 - 3장 연습문제 code

Lu175 2019. 8. 11. 01:36

_________________________________________________________________________________________________________

Q 01.

 

a = "Life is too short, you need python"

 

if "wife" in a :

    print("wife")

elif "python" in a and "you" not in a :

    print("python")

elif "shirt" not in a :

    print("shirt")

elif "need" in a :

    print("need")

else :

    print("none")

_________________________________________________________________________________________________________

->  shirt

_________________________________________________________________________________________________________

Q 02.

 

result = 0

i = 1

while i <= 1000 :

    if i % 3 == 0 :

        result += i

    i += 1

 

print(result)

_________________________________________________________________________________________________________

->  166833

_________________________________________________________________________________________________________

Q 03.

               

i = 0

while True :

    i += 1

    if (i > 5) :

        break

    print("*" * i)

_________________________________________________________________________________________________________

->  *

->  **

->  ***

->  ****

->  *****

_________________________________________________________________________________________________________

Q 04.

 

for i in range(1, 101) :

    print(i)

_________________________________________________________________________________________________________

->  1

->  2

->  3

->  

->  99

->  100

_________________________________________________________________________________________________________

Q 05.

 

A = [70, 60, 55, 75, 95, 90, 80, 80, 85, 100]

total = 0

for score in A :

    total += score

average = total / 10

print(average)

_________________________________________________________________________________________________________

->  79.0

_________________________________________________________________________________________________________

Q 06.

 

numbers = [1, 2, 3, 4, 5]

result = [x*2 for x in numbers if (x % 2) != 0]

print(result)

_________________________________________________________________________________________________________

->  [2, 6, 10]

_________________________________________________________________________________________________________