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="" while True: a=input() if a=="!!!!!": break words=words+" "+a words=words.split() s={} for i in words: if i in s: s[i]+=1 else: s[i]=1 s=list(s.items()) s.sort(key=lambda x:x[0]) print(len(s)) if len(s)<10: for i in range(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="" while True: a=input() if a=="!!!!!": break a=a.lower() for i in "!.,:*?": a=a.replace(i,' ') words=words+" "+a words=words.split() s={} for i in words: if i in s: s[i]+=1 else: s[i]=1 s=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

while True: 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)) else: print("f({:.2f})={:.2f}".format(a,2*a+1))

7-9 jmu-python-判断是否构成三角形 (10 分)

输入三角形的三边,判断是否能构成三角形。若能构成输出yes,否则输出no。

输入格式:

在一行中直接输入3个整数,3个整数之间各用一个空格间隔,没有其他任何附加字符。

输出格式:

直接输出yes或no,没有其他任何附加字符。

输入样例1: 3 4 5

输出样例1: yes

输入样例2: 1 2 3

输出样例2: no

s=input().split() a=int(s[0]) b=int(s[1]) c=int(s[2]) #a,b,c=int(input().split()) if aabs(b-c) and babs(a-c) and cabs(a-b): print("yes") else: print("no")

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

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

输入格式:

直接输入一个实数给 x,没有其他任何附加字符。

输出格式:

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

输入样例: 725

输出样例: f(725.000)=-1.000

import math a=eval(input()) if abs(a)>=300: print("f({:.3f})=-1.000".format(a)) else: print("f({:.3f})={:.3f}".format(a,a**3/math.log(abs(a)+2.6,10)))

7-11 jmu-python-猜数游戏 (10 分)

用户从键盘输入两个整数,第一个数是要猜测的数n(<10),第二个数作为随机种子,随机生成一个1~10的整数,如果该数不等于n,则再次生成随机数,如此循环,直至猜中数n,显示“N times to got it”,其中N为猜测的次数。

输入格式:

直接输入两个整数,以空格间隔。其中第一个数为要猜测的数,第二个数是随机种子

输出格式:

N times to got it

输入样例: 4 10

输出样例: 7 times to got it

import random a,x=map(int,input().split()) random.seed(x) c=random.randint(1,10) count=0 while True: count+=1 if c==a: print("{} times to got it".format(count)) break else: c=random.randint(1,10)

7-12 jmu_python_最大公约数&最小公倍数 (10 分)

本题要求从键盘输入两个整数(以逗号间隔),编程求出这两个数的最大公约数和最小公倍数

提示:求最大公约数可用辗转相除法,最小公倍数用两数的积除以最大公约数

输入格式:

在一行中输入两个整数,以逗号间隔

输出格式:

输出“GCD:a, LCM:b",其中a为求出的最大公约数,b为求出的最小公倍数

注意:在逗号后面有个空格

输入样例: 12,14

输出样例: GCD:2, LCM:84

import math a,b=map(int,input().split(',')) print("GCD:{:}, LCM:{:}".format(math.gcd(a,b),int(a*b/math.gcd(a,b))))

7-13 jmu_python_是否是数 (10 分)

本题要求从键盘输入一个字符串,判断该串是否属于整数、浮点数或者复数的表示

输入格式:

输入一个字符串

输出格式:

输出yes或no

输入样例: -299

输出样例: yes

a=input() try: a=eval(a) if type(a)==int or type(a)==float or type(a)==complex: print("yes") else: print("no") except: print("no")

7-14 jmu-python-输入输出-计算字符串中的数 (10 分)

将字符串中的每个数都抽取出来,然后统计所有数的个数并求和。

输入格式:

一行字符串,字符串中的数之间用1个空格或者多个空格分隔。

输出格式:

第1行:输出数的个数。

第2行:求和的结果,保留3位小数。

输入样例: 2.1234 2.1 3 4 5 6

输出样例: 6 22.223

a=input().split() print(len(a)) sum=0 for i in a: sum+=eval(i) print("{:.3f}".format(sum))

7-47 jmu-python-凯撒密码加密算法 (10 分)

编写一个凯撒密码加密程序,接收用户输入的文本和密钥k,对明文中的字母a-z和字母A-Z替换为其后第k个字母。

输入格式:

接收两行输入,第一行为待加密的明文,第二行为密钥k。

输出格式:

输出加密后的密文。

输入样例:

在这里给出一组输入。例如: Hello World! 3

输出样例:

在这里给出相应的输出。例如: Khoor Zruog!

s=input() mod=int(input()) a="abcdefghijklmnopqrstuvwxyz" A="ABCDEFGHIJKLMNOPQRSTUVWXYZ" for i in s: if 'a'<=i<='z': c=a.find(i) print(a[(c+mod+26)%26],end='') elif 'A'<=i<='Z': c=A.find(i) print(A[(c+mod+26)%26],end='') else: print(i,end="")

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值