본문 바로가기
Programming/python

[python] 파이썬 연습

by 그렉그의 2023. 2. 28.

오늘은 나도코딩님과 함께 python을 시작! 

# from random import *

# list = range(1, 21)

# # print(list)
# # shuffle(list)
# # print(list)
# # print(sample(list, 1))

# chicken = sample(list, 1)
# coffee = sample(list, 3)

# print("the chicken goes to", chicken)
# print("the coffee goes to", coffee)

# weather = int(input("what's the weather?"))

# if weather == 23:
# print("umbrella")
# else:
# print("no")


 

startbucks = ["a", "b", "c", "d"]

for potato in startbucks:
print("{0}, coffee ready".format(potato))
customer = "a"
index = 5
while index >= 1:
print("{0}, your coffee is ready.you have {1} left".format(customer, index))
index = index-1
if index == 0:
print("none")
customer = "a"
person = "unknown"

while person != customer:
print("{0}, coffee is ready".format(customer))
person = input("what's your name?")
if person == customer:
print("here is your coffee")
absent = [2, 5]
no_book = [7]
for student in range(1, 11):
if student in absent:
continue
elif student in no_book:
print("{0}, follow me".format(student))
break
print("{0}, read".format(student))
student = ["as", "asd", "asdf"]

number = [i.upper() for i in student]

print(number)
 
from random import *

count = 0

for i in range(1, 51):
time = randrange(5, 51)
if 5 < time < 15:
print("[o] {0}st customer has {1}duration".format(i, time))
count += 1
else:
print("[] {0}st customer has {1}duration".format(i, time))

print("total number of customer is {0}" .format(count))
 
def open_account():
print("ss")


def deposit(balance, money):
print("your balance is {0}".format(balance+money))
return balance + money


def withdrawal(balance, money):
if balance >= money:
print("your withdrawal is {0}".format(balance-money))
return balance - money
else:
print("you cannot withdrawal")
return balance


def withdraw_night(balance, money):
comission = 100
return comission, balance - money - balance


balance = 0
balance = deposit(balance, 100)
balance = withdrawal(balance, 2000)
comission, balance = withdraw_night(balance, 500)

print("comission is {0} and balance is {1}".format(comission, balance))

 

def profile(name, age, main_lang):
print("name = {0}, age:{1}, main_lang:{2}".format(name, age, main_lang))


profile("asf", 20, "23")
 
def profile(name, age, *language):
print("{0},{1}".format(name, age), end="")
for lan in language:
print(lan, end="")
print()


profile("k", 23, "kot", "ii")
지역변수

 

gun = 10


def checkpoint(soldiers):
global gun
gun = gun - soldiers
print("{0}".format(gun))


def checkpoint_ret(gun, soldiers)


gun = gun - soldiers
print("{0}".format(gun))
return gun


checkpoint(2)
print("{0}".format(gun))
 
def std_weight(height, gender):
   if gender == "man":
        return height * height * 22
   else:
        return height * height * 21


height = 175
gender = "man"
weight = round(std_weight(height/100, gender), 2)
print("the standard weight of height {0}cm man is {1}".format(height, weight))
a

 

# 3자리 마다 콤마 찍기
print("{0:,}".format(1000000))

print("{0:+<12,}".format(10000000000000))

 

 

파일 만들기 

score_file = open("score.txt","w",encoding ="utf8")
print("a :50", file=score_file)
print("b :20", file=score_file)
score_file.close()