需要钱给⽤户、现在只有50元python_python编程题现需要统计若⼲段⽂字(英⽂)中的不同单词数量。
如果不同的单词数量不超过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):
lambda编程
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 "!.,:*?":
place(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))

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。