cccc天梯赛python(cccc天梯赛一等奖)

发布时间:2022-11-13

本文目录一览:

  1. python中pprint在哪个包
  2. 问道python题?
  3. python判断读取哪一行数据读错了?

python中pprint在哪个包

在pprint包中

import pprint
tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead',
    ('parrot', ('fresh fruit',))))))))
stuff = ['a' * 10, tup, ['a' * 30, 'b' * 30], ['c' * 20, 'd' * 20]]
pprint.pprint(stuff)

输出结果如下:

['aaaaaaaaaa',
 ('spam',
  ('eggs',
   ('lumberjack',
    ('knights', ('ni', ('dead', ('parrot', ('fresh fruit',)))))))),
 ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
 ['cccccccccccccccccccc', 'dddddddddddddddddddd']]

问道python题?

# encoding: utf-8
# Python 3.6.0
# 判断输入的两个字符串在忽略大小写和空格的情况下是否相同
s1 = input("请输入第一行字符串:")
s2 = input("请输入第二行字符串:")
s1 = s1.upper().replace(' ', '')
s2 = s2.upper().replace(' ', '')
if s1 == s2:
    print('YES')
else:
    print('No')

python判断读取哪一行数据读错了?

for line in sj1:

这样读出来是没有行号的。你可以在

res1 = re.search(patternPage, line, re.M|re.I)

后加上

if res1 is None:
    print(line)

这样可以输出出错的行的内容。 或者在 for 之前定义一个变量 i_line=0,然后在循环中增加行号:

i_line = 0
for line in sj1:
    i_line = i_line + 1
    res1 = re.search(patternPage, line, re.M|re.I)
    if res1 is None:
        print(f'ERROR: not patternPage at (line {i_line}): {line}')
        continue
    l = int(res1.group(1))