1 Star 0 Fork 0

zhao-shu-bo/czsf

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
8 2.78 KB
Copy Edit Raw Blame History
zhao-shu-bo authored 2021-11-04 23:09 +08:00 . add 8.
def rect_area(width,height):
area = width * height
return area
def print_area(width,height):
area = width * height
print("{0} x {1} 长方形的面积:{2}".format(width,height,area))
def rect_area(width,height):
area = width * height
return area
def print_area(width,height):
area = width * height
print("{0} x {1} 长方形的面积:{2}".format(width,height,area))
def rect_area(width,height):
area = width * height
return area
r_area = rect_area(320,480)
print("{0}x{1} 长方形的面积:{2:.2f}".format(320,480,r_area))
r_area = rect_area(width=320,height=480)
print("{0}x{1} 长方形的面积:{2:.2f}".format(320,480,r_area))
r_area = rect_area(height=480,width=320)
print("{0}x{1} 长方形的面积:{2:.2f}".format(320,480,r_area))
def make_coffee(name="卡布奇诺"):
return "制作一杯{0}咖啡。".format(name)
coffee1 = make_coffee("拿铁")
coffee2 = make_coffee()
print(coffee1)
print(coffee2)
def sum(*numbers):
total=0.0
for number in numbers:
total += number
return total
print(sum(100.0,20.0,30.0))
print(sum(30.0,80.0))
def show_info(**info):
print('-----show_info-----')
for key, value in info.items():
print('{0}-{1}'.format(key,value))
print(show_info(name='Tony', age = 18,sex = True))
print(show_info(student_name='Tony', student_no='1000'))
x = 20
def print_value1():
x = 10
print("函数中的x = {0}".format(x))
print_value1()
print("全局变量x = {0}".format(x))
x = 20
def print_value2():
global x
x = 10
print("函数中的x = {0}".format(x))
print_value2()
print("全局变量x = {0}".format(x))
def add(a,b):
return a + b
def sub(a,b):
return a - b
def square(a):
return a * a
def calc(opr):
if opr == '+':
return add
elif opr == '-':
return sub
elif opr == '^ 2':
return square
f1 = calc('+')
f2 = calc('-')
f3 = calc('^ 2')
print('10 + 5 = {0}'.format(f1(10,5)))
print('10 - 5 = {0}'.format(f2(10,5)))
print('4 ^ 2 = {0} '.format(f3(4)))
def f4(x):
return x > 50
data1 = [66,15,91,28,98,50,7,80,90]
filtered = filter(f4,data1)
data2 = list(filtered)
print(data2)
def f5(x):
return x * 2
data3 = [66,15,91,28,98,50,7,80,90]
mapped = map(f5,data3)
data4 = list(mapped)
print(data4)
def calc(opr):
if opr == '+':
return lambda a,b :(a + b)
else:
return lambda a,b :(a - b)
f1 = calc('+')
f2 = calc('-')
print("10 + 5 = {0}".format(f1(10,5)))
print("10 - 5 = {0}".format(f2(10,5)))
data1 = [66,15,91,28,98,50,7,80,99]
filtered =filter(lambda x : (x>50),data1)
data2 = list(filtered)
print(data2)
mapped = map(lambda x : (x * 2),data1)
data3 = list(mapped)
print(data3)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhao-shu-bo/czsf.git
git@gitee.com:zhao-shu-bo/czsf.git
zhao-shu-bo
czsf
czsf
master

Search