목록2024/08 (7)
꼬물꼬물 개발자
# listday_of_week = ["Mon", "Tue", "Wed", "Thu", "Fri"]print(day_of_week[2])day_of_week.append("sun")print(day_of_week)day_of_week.remove("sun")print(day_of_week)day_of_week.clear()print(day_of_week)# Tuples : 불변days = ("Mon", "Tue", "Wed", "Thu", "Fri")print(days[-1])# dictionary : kdy - value 키-값 player = { 'name': 'gowoon', 'age': 42, 'alive': True, 'fav_food': ["피자", "햄버거"]}print(player)..
# Python Standard Library 사용법import random#from random import randint# if 함수pc_choice = random.randint(1, 50)user_choice = int(input("Choose number."))if user_choice == pc_choice: print("You won!")elif user_choice > pc_choice: print("Lower! Computer chose", pc_choice)elif user_choice pc_choice: print("Higher! Computer chose", pc_choice) # while 함수distance = 0while distance 20: print(f"I'm ..
# 음주 가능 나이 계산기# input 함수age = input("How old are ypu?")print("user answer", age)# type 함수print(type(age))print("-------------")# type 변경age = int(input("How old are ypu?"))# and : 조건이 모두 True 이면 True# or : 조건이 하나만 True 여도 Trueif age 18: print("You can't drink.")elif age >= 18 and age 35: print("You drink beer!")elif age == 60 or age == 70: print("Birthday party!")else: print("Go ahead!")결과
# 조건문1 : 조건문이 True면 다음 명령을 실행하라a = "gowoon"if a == "gowoon": print(f"{a}, 환영합니다!")# 조건문2 : password가 True면 A실행, False면 B실행password_correct = Falseif password_correct: print("Here is your money") #Aelse: print("Wrong password") #B# 조건문3 : winner가 10보다 크면 A실행, 10보다 작으면 B실행, 10이면 C실행 winner = 10if winner > 10: print("Winner is greater than 10") #Aelif winner print("Winner is less than 10") #B..
# Return Valuse 1def tax_calc(money): return money * 0.35def pay_tax(tax): print("thank you for paying", tax)to_pay = tax_calc(150)pay_tax(to_pay)pay_tax(tax_calc(150))# Return Valuse 2 my_name = "gowoon"my_age = 42my_color_eyes = "brown"# f"{변수} + 문자열"print(f"Hello I'm {my_name}, I have {my_age} years in the earth, {my_color_eyes} is my eye color")# practicedef make_juice(fruit): return f"{f..
# Functionsdef say_hello(): print("hello how r u?")say_hello()# Indentationdef say_bye(): print("bye bye") say_hello()say_bye()# Parametersdef say_hello(user_name): # user_name = parameter print("hello", user_name, "how are you?")say_hello("gowoon") # gowoon = argument (data)say_hello("nico")say_hello("lynn")say_hello("ralph")# Multiple Parametersdef say_hello(user_name, user_age): print(..