"Martial Arts Cheats" python

Topic:
Xiao Ming went to X cave to explore and found a damaged martial arts cheat book (more than 2000 pages! Of course it is forged).
He noticed that the 10th and 11th pages of the book are on the same paper, but the 11th and 12th pages are not on the same paper.
Xiao Ming only wants to practice martial arts from page 81 to page 92 of the book, but doesn't want to bring the whole book. May I ask how many pieces of paper he must tear off at least to take away?

1

sum = 0
def func(a,b):
    global sum
    if a%2!=0 and b%2==0 or a%2==0 and b%2!=0:
        sum=sum+(b - a + 1)/2 +1
    else:
        a%2==0 and b%2==0 or a%2!=0 and b%2!=0
        sum=sum+(b - a )/2 + 1
   
func(81,92)
print('至少要撕下%d页'%sum)
至少要撕下7

2

def func(a,b):
    sum = 0
    if a%2!=0 and b%2==0 or a%2==0 and b%2!=0:
        sum=sum+(b - a + 1)/2 +1
    else:
        a%2==0 and b%2==0 or a%2!=0 and b%2!=0
        sum=sum+(b - a )/2 + 1
    return sum
sum=func(81,92)
print('至少要撕下%d页'%sum)

至少要撕下7

Guess you like

Origin blog.csdn.net/weixin_53776140/article/details/112872700