Catch fox game 抓狐狸Python代码实现
实验描述
Write a program to simulate a fox catching game. Suppose there are a total of 5 holes in a row. The little fox is initially in one of the holes, and then the player opens a hole randomly. If there is a fox in it, he catches it. If there are no foxes in the hole, they will come again the next day, but the next day the fox will jump to the next hole before the player comes.
编写程序,模拟抓狐狸小游戏。假设一共有一排5 个洞口,小狐狸最开始的时候在其中一个洞口,然后玩家随机打开一个洞口,如果里面有狐狸就抓到了。如果洞口里没有狐狸就第二天再来抓,但是第二天狐狸会在玩家来抓之前跳到隔壁洞口里。
实验目的
- Develop the ability to analyze problems and model them.
- Skillfully use lists to solve practical problems.
- Skillfully use the selection structure and cyclic structure to solve practical problems.
- Understand the execution flow of the loop structure with an else clause.
- Understand the use of exception handling structures to constrain user input.
1、培养分析问题并对进行建模的能力。
2、熟练使用列表解决实际问题。
3、熟练运用选择结构和循环结构解决实际问题。
4、理解带else 子句的循环结构执行流程。
5、理解使用异常处理结构约束用户输入的用法。
上代码
from random import *
def mai():
print(