Python实验一

程序片段编程题

  1. 题库:销售利润预测
    【问题描述】

一家公司的年利润通常是其销售总额的25%,请编写一个程序,让用户输入预计的销售总额,然后显示其可能带来的利润。提示:

用数值0.25来代表25%。
【输入形式】

从键盘输入销售总额,销售总额可以是整数也可以是小数
【输出形式】

The profit is: 小数

【样例输入】

100000

【样例输出】

The profit is: 25000.0

sales=eval(input())
profit=sales*0.25
print("The profit is:",profit)
  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

total=consumption+tip+tax
print("The consumption is %.4f, the tip is %.4f, the tax is %.4f,so the total consumption is %.4f"%(consumption,tip,tax,total))

编程题

  1. 题库:平面上的两点间距离计算 - 《Python编程基础及应用》习题3-13
    【问题描述】

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

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

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

【输入形式】

点A的X坐标 , 点A的Y坐标
点B的X坐标 , 点B的Y坐标

【样例输入】

15,-189
22,176

【样例输出】

365.07
提示:X,Y坐标之间用逗号分割。

import math
Ax,Ay=eval(input())
Bx,By=eval(input())
L=math.sqrt((Ax-Bx)*(Ax-Bx)+(Ay-By)*(Ay-By))
print('%.2f'%L)
  1. 题库:土地面积计算
    【问题描述】

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

【输入形式】

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

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

1234567
【样例输出】

The land area is 28.342

X=eval(input())
L=X/43560
print('The land area is %.3f'%L)
  1. 题库:性别比例
    【问题描述】

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

【输入形式】

男生人数

女生人数

【输出形式】

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%

X=eval(input())
Y=eval(input())
M=(X/(X+Y))*100
F=(Y/(X+Y))*100
print('The male students ratio is %.2f%%,the female students ratio is %.2f%%'%(M,F))
  1. 题库:计算跑道长度
    【问题描述】

输入飞机的名称、加速度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.

n=input()#名称
a=eval(input())#加速度
v=eval(input())#起飞速度
L=(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.'%(n,a,v,L))
  1. 成功就是从失败到失败,也依然不改热情! - 《Python编程基础及应用》习题2-6
    【问题描述】

使用print( )函数打印输出下述内容。

Winston Churchill:“Success consists of going from failure to failure without loss of enthusiasm.”

【样例输出】

Winston Churchill:“Success consists of going from failure to failure without loss of enthusiasm.”

print('Winston Churchill:"Success consists of going from failure to failure without loss of enthusiasm."')
  1. My favorite sports are as follows -《Python编程基础及应用》习题2-7
    【问题描述】

按照以下格式打印输出。

【样例输入】


【样例输出】

My favorite sports are as follows:
football
table tennis
badminton
swimming
running
【样例说明】
第2 - 6行相较于第1行多一个制表符\t。符号皆英文符号。

print('My favorite sports are as follows:')
print('    football')
print('    table tennis')
print('    badminton')
print('    swimming')
print('    running')
  1. 小写到大写的转换 -《Python编程基础及应用》习题2-8
    【问题描述】

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

【输入形式】

英文字符串,可以包括英文字符,数字及符号。

【输出形式】

转换为大写后的英文字符串。

【样例输入】

cvoid2020
【样例输出】

CVOID2020

A=input()
B=A.upper()
print(B)
  1. 编程从键盘读入3个整数,输出它们的和与平均值 -《Python编程基础及应用》习题3-6
    【问题描述】

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

【输入形式】

整数1
整数2
整数3

【输出形式】

和,平均值

【样例输入】

1
2
3

【样例输出】

6,2.00
注意:和与均值间只有一个英文逗号,没有多余的空格。使用input( )函数时,不要添加输出参数,对于OJ而言,input(“提示信息”)中的提示信息也是输出的一部分,会影响OJ判题。

X=eval(input())
Y=eval(input())
Z=eval(input())
H=X+Y+Z
P=H/3
print('%d,%.2f'%(H,P))
  • 16
    点赞
  • 50
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谭你一个脑瓜崩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值