Python-100天代码

import turtle


turtle.pensize(4)
turtle.pencolor('red')
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.mainloop()
绘制正方形
f = float(input('输入华氏度温度:'))
c = (f - 32) / 1.8
print('%.1f华氏度 = %.1f摄氏度' % (f, c))
华氏度转摄氏度
import math


radius = float(input('输入圆的半径:')
perimeter = 2 * math.pi * radius
area = math.pi * radius * radius
print('周长:%.2f' % perimeter)
print('面积:%.2f' % area)
计算圆的周长和面积
year = int(input('输入年份'))
is_leap = year % 4 == 0 and year % 100 != 0 or year % 400 == 0
print(is_leap)
判断闰年
username = input('输入用户名')
password = input('输入口令')
# 如果希望输入口令时,没有回显,可使用getpass模块的getpass函数
# import getpass
# password = getpass.getpass('输入口令')
if nameuser == 'admin' and password == '12345':
    print('身份验证成功!')
else:
    print('身份验证失败!')
用户身份验证
"""
f(x) = 3 * x - 5 (x > 1)
f(x) = x + 2 (-1 < x <= 1)
f(x) = 5 * x + 3 (x <-1) 
"""

x = float(input('x = '))
if x > 1:
    y = 3 * x - 5
else:
    if x > -1:
        y = x + 2
    else:
        y = 5 * x + 3
print('f(%.2f) = %.2f' % (x, y))
分段函数求值

猜你喜欢

转载自www.cnblogs.com/ShuComputerProgram/p/10829125.html