首页 > 编程语言 > 详细

PTA的Python练习题(六)

时间:2020-02-09 11:45:31      阅读:132      评论:0      收藏:0      [点我收藏+]

从 第3章-8 字符串逆序 开始

1.

技术分享图片

n = str(input())
n1=n[::-1]
print(n1)

 

2.

技术分享图片

不是很好做这道题,自己还是C语言的思维,网上几乎也找不到什么答案

s = input()
idx = s.find("#")
s = s[:idx]
ss = s[:idx]
s_16 = "0123456789ABCDEFabcdef"

for c in s:
    if c not in s_16:
        s = s.replace(c, ‘‘)

flag = 0
for c in ss:
    if c in s_16:
        flag = ss.find(c)
        break

if - in ss[:flag]:
    s = - + s

if len(s) == 0:
    num_10 = 0
else:
    num_10 = int(s, 16)
print(num_10)

 

3.

技术分享图片

滤掉5个字母,还有空格和感叹号

a=input()
count=0
for i in range(0,len(a)):
    if(a[i]!=A and a[i]!=E and a[i]!=I and a[i]!=O and a[i]!=U and a[i]!=! and a[i]!=  and A<=a[i]<=Z):
        count=count+1
print(count)

 

4.

技术分享图片

我还在思考字符串怎么排序,发现其实之前做过的sort()函数可以用来无差别排序,一下子就简单了:

ls =list(input().split())
ls1=sorted(ls)
print("After sorted")
for i in ls1:
    print(i)

PTA的Python练习题(六)

原文:https://www.cnblogs.com/echoDetected/p/12286479.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!