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))
value = float(input('输入长度:')) unit = input('输入单位:') if unit == 'in' or unit == '英寸': print('%f 英寸 = %f 厘米' % (value, value * 2.54)) elif unit == 'cm' or unit == '厘米': print('%f 厘米 = %f 英寸' % (value, value / 2.54)) else: print('输入有效单位!')
from random import randint face = randint(1, 6) if face == 1: result = '唱歌' elif face == 2: result = '跳舞' elif face == 3: result = '学狗叫' elif face == 4: result = '俯卧撑' elif face == 5: result = '绕口令' else: result = '讲笑话' print(result)