1. Some different ways to delete elements from a string:
First, we can use 'strip()':
'''Actually, we can use 'strip()' which means delete ' ' from two sides of the code
to the middle'''
>>> s = ' bee'
>>> s.strip()
'bee'
>>> s = 'b e e'
>>> s.strip()
'b e e'
——————————————————————————————————————————————————————————————————————————
'''On the other side, not only can we delete ' ', but also other codes.
BE CAREFUL : JUST LIKE strip(), from two sides to middle!! '''
s = 'bed'
>>> s.strip('e')
'bed'
>>> s.strip('b')
'ed'
>>> s = 'bee'
>>> s.strip('e')
'b'
2.
Q : 要求统计给定整数M和N区间内素数的个数并对它们求和。
输入在一行中给出两个正整数M和N(1≤M≤N≤500)。
MAIN PART:
So the first time, I try to use these codes :
M,N = map(int,input().split())
count = 0
for i in range(M, N + 1):
for j in range(2, i):
if i % j == 0:
break
''' However, after each loop, we actually want to execute a judge which is
used to count the number of primer number.
So we can use: '''
M,N = map(int,input().split())
count = 0
for i in range(M, N + 1):
for j in range(2, i):
if i % j == 0:
break
if j == i-1:
count = count + 1