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))