Home  >  Article  >  Backend Development  >  Python written test questions: Designing a "jump-a-jump" mini-game scorer

Python written test questions: Designing a "jump-a-jump" mini-game scorer

little bottle
little bottleOriginal
2019-04-27 16:03:474180browse

Today I will show you a Python written test question designed to design a "jump" mini-game scorer. It has certain reference value and is also very simple and easy to learn. Friends who are interested can learn about it.

Title: Design the scoring function of the "Jump" game. In the "Jump" game, the black villain will get 1 point by jumping from one block to another.
If he jumps The center point of the block will get 2 points. Jumping to the center point continuously will get 2 points, 4 points, 6 points, etc. This function passes in a list.
The Boolean value True or False is used in the list to indicate whether to jump to the center point of the square. The function returns the last score obtained

def calc_score(jump_list):
    total = 0
    prev_on_center = False
    on_center_point = 2
    for val in jump_list:
        if val:
            total += on_center_point
            on_center_point += 2
            prev_on_center = True
        else:
            total += 1
            on_center_point = 2
            prev_on_center = False
    return total
    
def main():            //测试
    list1 = [True, False, False, True, True, True]
    list2 = [True, True, True, True, False, True, True]
    list3 = [False, False, True, True, True, True, True, False]
    print(calc_score(list1))  # 16
    print(calc_score(list2))  # 27
    print(calc_score(list3))  # 33

if __name__ == '__main__':
    main()

Related tutorials:Python Video tutorial

The above is the detailed content of Python written test questions: Designing a "jump-a-jump" mini-game scorer. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What can python do?Next article:What can python do?