Holes in the text Add problem to Todo list Problem code: HOLES, holestodo
1 import sys 2 3 4 def count_holes(letter): 5 hole_2 = ['A', 'D', 'O', 'P', 'Q', 'R'] 6 if letter == 'B': 7 return 2 8 elif letter in hole_2: 9 return 110 else:11 return 012 13 14 def main():15 n = int(sys.stdin.readline())16 for t in sys.stdin:17 num = 018 for l in t[:-1]:19 num += count_holes(l)20 print num21 22 23 main()
Learning
Raw_input () and sys. stdin. readline ()
Raw_input () does not contain the last line break of \ n, while the latter has
Sys. stdin. readline (). strip (), no parameter. By default, spaces and line breaks are removed.
. Spilt () and separate the input data by space.
IDE
Debug Comprehension
Console input cannot be displayed immediately
Because pycharm enables buffering
Psyco. full ()
Sometimes it does cause RE
Good code indentation and spaces
Predefined mode is faster
If a in B []
For Loop
No problem. You can use a loop String. If you do not want \ n (this question does not affect the result, but multiple functions are called), use [:-1: the operation is a great benefit of py.
Both the conception and debugging are independently completed.
Come on!
Error
Elif ('A' or 'D' or 'O' or 'P' or 'q' or 'R') = letter: the logical judgment is wrong, unavailable