第二、三章

1.小费、税和消费总额

【问题描述】

请编写一个程序来计算餐厅某次点餐的消费总额。程序要求用户输入点餐的费用,然后计算税率为10%的小费和税率为7%的消费税。最后显示各项金额和消费总额。小数点后保留4位小数。
【输入形式】

点餐消费总额
【输出形式】

The consumption is 【小数点后保留4位小数】, the tip is 【小数点后保留4位小数】, the tax is 【小数点后保留4位小数】,so the total consumption is 【小数点后保留4位小数】

【样例输入】

100
【样例输出】

The consumption is 100.0000, the tip is 10.0000, the tax is 7.0000,so the total consumption is 117.0000

代码:

consumption = eval(input())
tip = consumption*0.1
tax = consumption*0.07
total = consumption + tip + tax
print("THe consumption is %.4f, the tip is %.4f, the tax is %.4f,so the total \
is %.4f"%(consumption,tip,tax,total))

 2.小写到大写的转换

【问题描述】

从键盘读取一个英文字符串,将其转换为大写,然后输出。
【输入形式】

英文字符串,可以包括英文字符,数字及符号。
【输出形式】

转换为大写后的英文字符串。
【样例输入】

cvoid2020

【样例输出】

CVOID2020

代码:

sName = input()
print(sName.upper())

3.计算跑道长度

【问题描述】

  输入飞机的名称、加速度a(米/秒的平方)和起飞速度v(米/秒),根据以下公式计算飞机起飞所需要的最短跑道长度。

  length=v*v/(2a)

【输入形式】

  从键盘输入飞机名称、加速度a和起飞速度v,分三行输入

【输出形式】

 输出飞机的名称、加速度a、起飞速度v和最短跑道长度(结果保留2位小数)

【样例输入】

B350

3.572

60

【样例输出】

The acceleration of B350 is 3.57 M / s, the take-off speed is 60.00 M / s, and the shortest take-off runway length is 503.92 M.

代码:
 

sName = input()
a = float(input())
v = float(input())
length=v*v/(2*a)
print("The acceleration of %s is %.2f M / s, the take-off speed is %.2f M / s, and \
the shortest take-off runway length is %.2f M."%(sName,a,v,length))

4.性别比例

【问题描述】

编写一个程序,请用户输入某班级男生和女生的人数,然后显示该班级的性别比例,结果保留两位小数。

【输入形式】

男生人数

女生人数

【输出形式】

The male students ratio is 【百分比】,the female students ratio is 【百分比】

【样例输入1】

12

8

【样例输出1】

The male students ratio is 60.00%,the female students ratio is 40.00%

【样例输入2】

8

4

【样例输出2】

The male students ratio is 66.67%,the female students ratio is 33.33%

代码:

male = float(input())
female = float(input())
total = male + female
ratio1 = male/total
ratio2 = female/total
print("The male students ratio is %.2f%%,the female students ratio is %.2f%%"%(ratio1*100,ratio2*100))

5.土地面积计算

【问题描述】

一英亩土地等于43560平方英尺。请编写一个程序,让用户输入以平方英尺为单位输入一片土地的面积,然后计算并输出这片土地的英亩数。

【输入形式】

从键盘输入土地面积(可以是整数也可以是小数)
【输出形式】

土地的亩数(小数点后保留3位)
【样例输入】

1234567
【样例输出】

The land area is 28.342

代码:

a = float(input())
b = a/(43560)
print("The land area is %.3f"%(b))

6.平面上的两点间距离计算

【问题描述】

输入平面上两个点A和B的坐标,(x1,y1)和(x2,y2),完成如下任务:

  1. 要求使用者输入A,B的平面坐标共4个值;

  2. 计算并输出两点之间的距离,保留2位小数。

【输入形式】

点A的X坐标 , 点A的Y坐标 点B的X坐标 , 点B的Y坐标
【样例输入】

15,-189
22,176
【样例输出】
365.07

代码:

#第一种:
a = input().split(",")
b = input().split(",")
x1 = float(a[0])
y1 = float(a[1])
x2 = float(b[0])
y2 = float(b[1])
d = ((x1-x2)**2+(y1-y2)**2)**(1/2)
print(f"{d:.2f}")
#第二种:
x1,y1 = map(float,input().split(","))
x2,y2 = map(float,input().split(","))
d = ((x1-x2)**2+(y1-y2)**2)**(1/2)
print(f"{d:.2f}")

7.编程从键盘读入3个整数,输出它们的和与平均值 

【问题描述】

编程从键盘读入3个整数,输出它们的和与平均值。其中,平均值保留2位小数。
【输入形式】

整数1
整数2
整数3
【输出形式】

和,平均值
【样例输入】

1
2
3
【样例输出】
6,2.00

代码:

n1 = int(input())
n2 = int(input())
n3 = int(input())
total = n1+n2+n3
average = total/3
#第一种输出方式:
print(total,','f'{average:.2f}',sep='')
#第二种输出方式:
print('%d,%.2f'%(total,average))
  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值