python输入两个值都是字母_python编程题 - osc_wv1mxwu2的个人空间 - OSCHINA - 中文开源技术交流社区...

现需要统计若干段文字(英文)中的不同单词数量。如果不同的单词数量不超过10个,则将所有单词输出(按字母顺序),否则输出前10个单词。注1:单词之间以空格(1个或多个空格)为间隔。注2:忽略空行或者空格行。注3:单词大小写敏感,即'word'与'WORD'是两个不同的单词 。输入说明若干行英文,最后以!!!!!为结束。输出说明不同单词数量。 然后输出前10个单词(按字母顺序),如果所有单词不超过10...
摘要由CSDN通过智能技术生成

现需要统计若干段文字(英文)中的不同单词数量。

如果不同的单词数量不超过10个,则将所有单词输出(按字母顺序),否则输出前10个单词。

注1:单词之间以空格(1个或多个空格)为间隔。

注2:忽略空行或者空格行。

注3:单词大小写敏感,即'word'与'WORD'是两个不同的单词 。

输入说明

若干行英文,最后以!!!!!为结束。

输出说明

不同单词数量。 然后输出前10个单词(按字母顺序),如果所有单词不超过10个,则将所有的单词输出。

输入样例

Failure is probably the fortification in your pole

It is like a peek your wallet as the thief when you

are thinking how to spend several hard-won lepta

when you Are wondering whether new money it has laid

background Because of you, then at the heart of the

most lax alert and most low awareness and left it

godsend failed

!!!!!

输出样例

49

Are

Because

Failure

It

a

alert

and

are

as

at

words=""

whileTrue:

a=input()if a=="!!!!!":breakwords=words+" "+a

words=words.split()

s={}for i inwords:if i ins:

s[i]+=1

else:

s[i]=1s=list(s.items())

s.sort(key=lambda x:x[0])

print(len(s))if len(s)<10:for i inrange(len(s)):

word,count=s[i]

print(word)else:for i in range(10):

word,count=s[i]

print(word)

7-2 jmu-Java&Python-统计文字中的单词数量并按出现次数排序 (25 分)

现在需要统计若干段文字(英文)中的单词数量,并且还需统计每个单词出现的次数。

注1:单词之间以空格(1个或多个空格)为间隔。

注2:忽略空行或者空格行。

基本版:

统计时,区分字母大小写,且不删除指定标点符号。

进阶版:

统计前,需要从文字中删除指定标点符号!.,:*?。 注意:所谓的删除,就是用1个空格替换掉相应字符。

统计单词时需要忽略单词的大小写。

输入说明

若干行英文,最后以!!!!!为结束。

输出说明

单词数量

出现次数排名前10的单词(次数按照降序排序,如果次数相同,则按照键值的字母升序排序)及出现次数。

输入样例1

failure is probably the fortification in your pole

it is like a peek your wallet as the thief when you

are thinking how to spend several hard-won lepta

when you are wondering whether new money it has laid

background because of you then at the heart of the

most lax alert and most low awareness and left it

godsend failed

!!!!!

输出样例1

46

the=4

it=3

you=3

and=2

are=2

is=2

most=2

of=2

when=2

your=2

words=""

whileTrue:

a=input()if a=="!!!!!":breaka=a.lower()for i in "!.,:*?":

a=a.replace(i,' ')

words=words+" "+a

words=words.split()

s={}for i inwords:if i ins:

s[i]+=1

else:

s[i]=1s=list(s.items())

s.sort(key=lambda x:x[0])

s.sort(key=lambda x:x[1],reverse=True)

print(len(s))for i in range(10):

word,count=s[i]

print("{}={}".format(word,count))

7-3 jmu-python-汇率兑换 (10 分)

按照1美元=6人民币的汇率编写一个美元和人民币的双向兑换程序

输入格式:

输入人民币或美元的金额,人民币格式如:R100,美元格式如:$100

输出格式:

输出经过汇率计算的美元或人民币的金额,格式与输入一样,币种在前,金额在后,结果保留两位小数

输入样例1:

R60

输出样例1:

$10.00

输入样例2:

$5

输出样例2:

R30.00

a=""a=input()if a[0]=="R":

print("${:.2f}".format(eval(a[1:])/6))else:

print("R{:.2f}".format(eval(a[1:])*6))

7-4 jmu-python-九九乘法表(矩形) (10 分)

本题目要求输出如下图所示的九九乘法表

注:乘积要求做格式控制,占4个位置的宽度

输入样例:

输出样例:

1*1=1 1*2=2 1*3=3 1*4=4 1*5=5 1*6=6 1*7=7 1*8=8 1*9=9

2*1=2 2*2=4 2*3=6 2*4=8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18

3*1=3 3*2=6 3*3=9 3*4=12 3*5=15 3*6=18 3*7=21 3*8=24 3*9=27

4*1=4 4*2=8 4*3=12 4*4=16 4*5=20 4*6=24 4*7=28 4*8=32 4*9=36

5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 5*6=30 5*7=35 5*8=40 5*9=45

6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 6*7=42 6*8=48 6*9=54

7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49 7*8=56 7*9=63

8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 8*9=72

9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81

for i in range(1,10):for j in range(1,10):

print("{}*{}={:<4}".format(i,j,i*j),end="")

print()

7-5 jmu-python-回文数判断(5位数字) (10 分)

本题目要求输入一个5位自然数n,如果n的各位数字反向排列所得的自然数与n相等,则输出‘yes’,否则输出‘no’。

输入格式:

13531

输出格式:

yes

输入样例1:

13531

输出样例1:

yes

输入样例2:

13530

输出样例2:

no

n =input()if n==n[::-1]:

print("yes")else:

print("no")

7-7 jmu-python-输入输出-处理不定行输入 (1 分)

处理一段文字(可能有很多行,行数不确定),输出每行包含的单词数(单词之间以空格或多个空格分隔)。

注意:处理的时候要忽略掉空行或者空格行。

提示: 使用如下代码来处理不定行输入

while True:

try:

your code

except:

break

输入样例:

1 2

bcd efg hij

x

输出样例:

2

3

1

whileTrue:

a=input()try:

a=a.split()if(len(a))>0:

print(len(a))

except:break

7-8 jmu-python-分段函数 (10 分)

本题目要求计算下列分段函数f(x)的值(x为从键盘输入的一个任意实数):

输入格式:

输入在一行中给出实数 x。

输出格式:

在一行中按“f(x)=result”的格式输出,其中x与result都保留两位小数。

输入样例:

0.76

输出样例:

f(0.76)=1.20

a=eval(input())if a<3:

print("f({:.2f})=1.20".format(a))

elif a==3:

print("f({:.2f})=10.00".format(a))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值