pta 6 turned over Python3

"666" is an Internet slang, which probably means that someone is very powerful and we admire them very much. Recently, another number "9" has been derived, which means "6 turned over", which is really awesome. If you think this is the highest state of awesomeness, you are wrong - the current highest state is the number "27", because it is 3 "9"!

This question asks you to write a program to translate those outdated sentences that only use a series of "6666...6" to express admiration into the latest advanced expressions.

Input format:

Enter a sentence in one line, that is, a non-empty string consisting of no more than 1000 English letters, numbers and spaces, ending with a carriage return.

Output format:

Scan the input sentence from left to right: if there are more than 3 consecutive 6s in the sentence, replace the consecutive 6s with 9s; but if there are more than 9 consecutive 6s, replace the consecutive 6s with 27. Other content will not be affected and will be output as is.

Input example:

it is so 666 really 6666 what else can I say 6666666666

Output sample:

it is so 666 really 9 what else can I say 27

Analysis:

Introduce the re library, first look for more than 9 "6", that is, look for exactly 10 "6", change these 10 "6" to 27, and then look for more than 3 "6", that is, look for exactly 4 For "6", change these 10 "6"s into 9s.

Python code:

import re
a = input()
a = re.sub(r'6{10,}','27',a)
a = re.sub(r'6{4,}','9',a)
print(a)

Submit results:

Guess you like

Origin blog.csdn.net/weixin_51756038/article/details/134365439