您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Python笔试题之设计“跳一跳”小游戏计分器

2025/11/19 1:48:48发布33次查看
今天带大家见识一道python笔试题之设计“跳一跳”小游戏计分器,具有一定的参考价值,也非常简单易学,感兴趣的朋友可以了解一下。
题目: 设计“跳一跳”游戏的计分函数,“跳一跳”游戏中黑色小人从一个方块跳到另一个方块上会获得1分,
如果跳到方块的中心点上会获得2分,连续跳到中心点会依次获得2分、4分、6分、……。该函数传入一个列表,
列表中用布尔值true或false表示是否跳到方块的中心点,函数返回最后获得的分数
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)) # 33if __name__ == '__main__': main()
相关教程:python视频教程
以上就是python笔试题之设计“跳一跳”小游戏计分器的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product