******
20230213
******
# 创建函数——摄氏度转化为华氏度
def fahrenheit_converter(C):
fahrenheit = C * 9/5 + 32
return str(fahrenheit) +'℉'
C2F = fahrenheit_converter(35)
print(C2F)
******
#创建函数——摄氏度转化为华氏度 (升华版)
def fahrenheit_converter(C):
fahrenheit = C * 9/5 + 32
print(str(fahrenheit) +'℉')
C2F = fahrenheit_converter(35)
print(C2F)
******
# 练习题1(初级) 设计一个重量转换器,输入以“g”为单位的数字后返回换算成“kg”的结果
def kgweight_converter(g):
kgweight = g/1000
return str(kgweight) + 'kg'
# g = input("write down a weight value: ")
# temp = int(g)
# g2kg = kgweight_converter(temp)
# print(g2kg)
g= int(input("write down a weight value: "))
g2kg = kgweight_converter(g)
print(g2kg)
******
# 练习题2(中级) 设计一个求直角三角形斜边长的函数(两条直角边为参数,求最长边)
def lsrtriangle(a,b):
t = a**2 + b**2
c = pow(t,0.5)
return str(c)
# lsrt = lsrtriangle(3,4)
# print(lsrt)
# a = int(input("write down the a number: "))
# b = int(input("write down the b number: "))
# lsrt = lsrtriangle(a,b)
# print(lsrt)
t = input("a,b =")
a = int(t.split(",")[0])
b = int(t.split(",")[1])
lsrt = lsrtriangle(a,b)
print(lsrt)
******