1.Python编程之入门

Python - 100天从新手到大师 (感谢作者:骆昊)学习笔记
Day01 - 初识Python
Day02 - 语言元素
练习:
1.将华氏温度转换为摄氏温度F = 1.8C + 32
f = float(input('请输入华氏温度: '))
c = (f - 32) / 1.8
print('%.1f华氏度 = %.1f摄氏度' % (f, c))

2.输入半径计算圆的周长和面积
import math

r = (float)(input("输入圆的半径:"))
perimeter = 2 * math.pi*r
print(perimeter)
area = math.pi * r * r
print(area)

3.输入年份 如果是闰年输出True 否则输出False
year = input("输入年份:")
is_leap = (year % 4 == 0 and year % 100 != 0 or year % 400 == 0)
print(is_leap)
报错:TypeError: not all arguments converted during string formatting



主要是因为运算符%前面和后面的参数数据类型不对应
修改后:
year = (int)(input("输入年份:"))
is_leap = (year % 4 == 0 and year % 100 != 0 or year % 400 == 0)
print(is_leap)

你可能感兴趣的:(1.Python编程之入门)