Home > Backend Development > Python Tutorial > 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
Release: 2019-04-27 16:05:15
Original
4354 people have browsed it

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()
Copy after login

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!

Related labels:
source:今天带大家见识一道Python笔试题之设计“跳一跳”小游戏计分器,具有一定的参考价值,也非常简单易学,感兴趣的朋友可以了解一下。
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template