PTA的Python练习题

Posted Ch0bits

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PTA的Python练习题相关的知识,希望对你有一定的参考价值。

从 第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练习题的主要内容,如果未能解决你的问题,请参考以下文章

PTA的Python练习题

PTA的Python练习题

PTA的Python练习题(十九)

PTA的Python练习题(十五)

PTA的Python练习题

PTA的Python练习题(十六)