自学Python-1

#格式化输出:%s/%d%f、format

name ='jimmy'

age =30

gender ='男'

high =180

print('我的名字叫%s,今年%s岁,我是一个%s人,我的身高是%scm'%(name,age,gender,high))

fruit ='西瓜'

heavy =3.25

price =1.33

print('这个%s重%s斤,每斤的价格是%s元,总价是%0.2f元'%(fruit,heavy,price,heavy*price))

print('这个{}重{}斤,每斤的价格是{}元,总价是{:.2f}元'.format(fruit,heavy,price,heavy*price))

name =input('请输入英雄名')

skill =input('请输入英雄技能')

print('{}的技能是{}'.format(name, skill))

num=int(input('请输入数字'))

print('{}%'.format(num))

#if判断

day =input('请输入一个节日')

if day =='情人节':

print('{}要吃烛光晚餐'.format(day))

num1 =float(input('请输入一个数字'))

num2 =float(input('请再输入一个数字'))

count =input('请输入一个运算符(+-*/)')

if count =='+':

print('{}+{}={}'.format(num1, num2, num1 + num2))

elif count =='-':

print('{}-{}={}'.format(num1, num2, num1 - num2))

elif count =='*':

print('{}*{}={}'.format(num1, num2, num1 * num2))

elif count=='/':

print('{}/{}={}'.format(num1, num2, num1 / num2))

else:

print('运算符输入有误')

year =int(input('请输入一个年份'))

if (year %4 ==0)and (year %100 ==0)or (year %400 ==0):

print('{}是闰年'.format(year))

else:

print('{}是平年'.format(year))

你可能感兴趣的:(自学Python-1)