2021-01-01 python学习笔记(1)

下面是一些python学习过程中的小程序示例:

一,华氏温度和摄氏温度相互转换的小示例:

#TempConvert.py
TempStr = input("请输入带有符号的温度值:")
if  TempStr[-1] in ['F','f']:
      C = (eval(TempStr[0:-1]) - 32)/1.8
      print("转换后的温度是{:.2f}C".format(C))
elif TempStr[-1] in ['C','c']:
      F = 1.8*eval(TempStr[0:-1])+32
      print("转换后的温度是{:.2f}F".format(F))
else:
      print("输入格式错误")

二,利用python中自带的turtle包画出蟒蛇:

#pythondraw.py
import turtle
turtle.setup(650,350,200,200)
turtle.penup()
turtle.fd(-250)
turtle.pendown()
turtle.pensize(25)
turtle.pencolor("purple")
turtle.seth(-40)
for i in range(4):
    turtle.circle(40,80)
    turtle.circle(-40,80)
turtle.circle(40,80/2)
turtle.fd(40)
turtle.circle(16,180)
tuetle.fd(40*2/3)
turtle.done()

三,pow()函数实现多次幂相乘:

#daydayup.py
dayfactor = 0.005
dayup = pow(1+dayfactor,365)
daydown = pow(1-dayfactor,365)
print("dayup={:.2f},daydown={:.2f}".format(dayup,daydown))

四,循环和判断的初步使用(一)

#daydayup2.py
dayup = 1.0
dayfactor = 0.01
for i in range(365):
    if i % 7 in [6,0]:
        dayup = dayup*(1-dayfactor)
    else:
        dayup = dayup*(1+dayfactor)
print("dayup={:.2f}".format(dayup))

五,循环和判断的初步使用(二)

#daydayup.py
def dayUP(df):
    dayup = 1
    for i in range(365):
        if i % 7 in [6,0]:
            dayup = dayup * (1-0.01)
        else:
            dayup = dayup * (1 + df)
    return dayup
dayfactor = 0.01
while dayUP(dayfactor) < 37.78:
    dayfactor += 0.001
print("dayup={:.3f}".format(dayfactor))

六,输入数字,输出相对应的星期几
字符串的初步处理

#weeknameprintV1.py
weekStr = "星期一星期二星期三星期四星期五星期六星期日"
weekId = eval(input("请输入星期数字(1-7):"))
pos = (weekId - 1) * 3
print(weekStr[pos:pos+3])

七,输入数字,输出相对应星期几(二)

#weknameprintv2.py
weekStr = "一二三四五六日"
weekId = eval(input("请输入星期数字(1-7):"))
print("星期" + weekStr[weekId-1])

你可能感兴趣的:(python,python,其他)