0% found this document useful (0 votes)
7 views2 pages

Python Functions Clean

The document contains Python code snippets demonstrating various programming concepts such as functions, conditionals, loops, and built-in functions like map, reduce, and filter. It includes examples of defining and calling functions, using global and local variables, and performing mathematical operations. Additionally, it showcases the use of lambda functions and how to manipulate lists and numbers.

Uploaded by

seungmiin1020
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Python Functions Clean

The document contains Python code snippets demonstrating various programming concepts such as functions, conditionals, loops, and built-in functions like map, reduce, and filter. It includes examples of defining and calling functions, using global and local variables, and performing mathematical operations. Additionally, it showcases the use of lambda functions and how to manipulate lists and numbers.

Uploaded by

seungmiin1020
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

##def##

L = list(range(1,11))
print(L)
print(len(L))

def print_list(a):
for i in a:
print(i)
print_list(L)

def boy():
print('I am a boy.')
print('You are a girl')

boy()

def functon(a,b):
if a > b:
print('a is greater than b')
elif a == b:
print('a is equal to b')
else:
print('a is less than b')

functon(10,100)

print(256 ** 4 == (2 ** 8) ** 4)

def numOfDight(a):
if a > 0:
print(len(str(a)))

numOfDight(31823719827391823)

def square(a):
for i in range(a,10):
for j in range(1,10):
print(f'{i} x {j} = {i * j}:2d')
square(6)

##return##
def f(x):
a, b = map(int, input().split())
y = a*x+b
return y

c = f(10)
print(c)

def f1(x,a,b):
return a*x+b

c = f1(10,10,10)
print(c)

def triangle(a,b):
return a*b//2

c = triangle(10,10)
print(c)

def korean_number(n):
number = {1:'1', 2:'2', 3:'3',
4:'4', 5:'5'}
return number[n]

print(korean_number(5))
def interest(p,r,t):
I = p*r*t
return I

def interest_amount(p,r,t):
A = p*(1+r*t)
return A

print(interest(10000000, 0.03875, 5))


print(interest_amount(10000000, 0.03875, 5))

##local/global##
def function1(n):
n = 100
print(n)

m = 1000
def function2(m):
print(m)
print(m)

def function1():
global l
l = 10000
print(l)

function1()
print(l)

count = 0

def increase():
global count
count = count + 1
print(count)

##lambda##
def hap(x, y):
return x + y

c = hap(10,20)
print(c)

b = (lambda x,y: x + y)(10,20)


print(b)

##map##
map(lambda x: x*2, [1,2,3,4,5])
print(list(map(lambda x: x*2, [1,2,3,4,5])))

map(lambda x : 0 if x < 10 else x, [1,2,3,4,5])

##reduce##
from functools import reduce
d = reduce(lambda x, y: x+y, [1,2,3,4,5])
print(d)

e = reduce(lambda x, y: y+x, 'abcde')


print(e)

##filter##
filter(lambda x: x <= 5, range(10))
print(list(filter(lambda x: x <= 5, range(10))))

You might also like