泉州信息工程学院,python PTA字符串

选择题:

T T F F F T F

填空题:

ACB    lower

程序填空题:

 编程题:

7-1:

s = input()
print("{:>8}".format(s if len(s) <= 8 else s[-8:]).replace(' ', '*'))

7-2:

n = int(input())
print(str(n).zfill(2))

7-3:

n = int(input())
binary = bin(n)[2:].zfill(8)
print(binary)

7-4:

s = input()
n = int(input())
if len(s) > n:
    s = s[:n]
else:
    s += '$' * (n - len(s))
print(s)

7-5:

s = input()
n = int(input())
words = s.split()
if len(words) > n:
    words = words[:n]
else:
    words += ['PAD'] * (n - len(words))
print(' '.join(words))

7-6:

name = input()
surname = name[:1]
given_name = name[1:]
print(f'你好,{name}同学。')
print(f'{surname}同学,很高兴认识你。')
print(f'{given_name}同学,我们交个朋友吧!')

7-7:

string = input()
char = input()

count = string.count(char)

print(count)

7-8:

s = input()
n = int(input())

s_copy = s * n
s_reverse = s[::-1] * n

print(s_copy)
print(s_reverse)

7-9:

s = input()
max_digit = '0'
max_index = 0

for i in range(len(s)):
    if s[i].isdigit() and s[i] > max_digit:
        max_digit = s[i]
        max_index = i

print(max_digit, max_index)

7-11:

s = input()
result = s.swapcase()
print(result)

7-14:

n = int(input())

max_len = 0
for i in range(n):
    s = input().lstrip()  # 去掉左侧空格
    max_len = max(max_len, len(s))

print("length={}".format(max_len))

7-15:

s = input().strip()

count = 0
for i in range(len(s)):
    if (i == 0 or s[i-1].isspace()) and not s[i].isspace():
        count += 1

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

7-16:

s = input()

s = s.replace(" ", "")

print(s)

7-17:

str1 = input().strip()
str2 = input().strip()
count = 0 
start = 0
while True:
    idx = str1.find(str2, start)
    if idx == -1:
        break
    count += 1
    start = idx +1
print(count)

7-19:

import datetime



# 读入身份证号

id_card = input().strip()



# 获取出生日期

birth_str = id_card[6:14]

birth_date = datetime.datetime.strptime(birth_str, '%Y%m%d').date()



# 判断是否具有报名资格

last_date = datetime.date(2022, 8, 31)

if (last_date - birth_date).days >= 6 * 365:

    print('yes')

else:

    print('no')

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值