Python 大佬帮忙看看

191 天前
 williamcc
#############################################################LV2############################################################
'''
看来你们已经基本掌握了条件语句和循环语句的基本用法了
利用今天所学完成最终测试吧
程序约精炼越好哦😀
得分越高越好哦😁

跳转到 153 行,开始吧😎!!!

'''
#######################################!!!!!中间这段别改哦!!!!!去 145 行哦!!!##############################################################################
import time # 导入时间模块
import sys
import random

####################################
x = 1 # 横向坐标默认值
y = 1 # 纵向坐标默认值
step_number = 0 # 记录行走步数的变量
star_number = 0 # 记录吃糖豆得分
start = time.time() # 获取开始时的时间戳
####################################13 21 4
map_list=[
[" ","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@"],
["=>","Y"," "," ","@","@"," "," "," "," "," "," ","@"," "," ","机器人创新协会"," ","@"],
[" ","@"," "," ","@","@","@","@"," "," ","@"," ","@"," "," "," ","第一次培训课"," "," ","@"],
[" ","@","O"," "," "," "," ","@"," ","@","@"," ","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@"],
[" ","@","@","@","@","@"," ","@"," ","@","@"," "," "," "," "," "," "," "," "," "," "," "," "," "," ","@","@","@","@","@","@"],
[" ","@"," "," "," ","@"," ","@"," ","@","@","@","@"," "," "," "," "," "," "," "," "," ","@"," "," ","@"," "," "," ","O","@"],
[" ","@"," ","@"," ","@"," ","@"," "," ","@","@","@"," "," "," "," "," "," "," "," "," ","@"," "," ","@"," ","@","@","@","@"],
[" ","@"," ","@"," "," "," ","@"," "," "," "," ","@","@","@","@","@","@","@","@","@","@","@"," ","@","@"," "," "," "," ","@"],
[" ","@"," ","@","@","@","@","@"," "," ","@"," ","@","@","@","@","@"," "," "," "," "," "," "," "," "," "," "," ","@"," ","@"],
[" ","@","O"," "," "," "," "," "," "," ","@"," ","@","O"," "," "," "," ","@","@","@","@","@"," ","@","@","@"," ","@"," "," ","=>"],
[" ","@"," ","@","@","@","@","@","@","@","@"," ","@","@","@","@","@"," ","@","@","@","@","@"," ","@","@","@"," ","@","@","@"],
[" ","@"," "," "," "," "," ","@"," ","@","@"," ","@","@","@","@","@"," ","@","@","@","O"," "," "," "," "," "," ","@","@","@"],
[" ","@","@","@","@","@"," ","@"," ","@","@"," ","@"," "," "," "," "," "," ","@","@","@","@","@","@","@","@"," ","@"," ","@"],
[" ","@"," "," "," "," ","O","@"," ","@","@"," ","@","@"," ","@","@","@"," "," "," "," "," "," ","O"," ","@"," "," "," ","@"],
[" ","@"," ","@","@","@","@","@"," "," "," "," "," "," "," ","@","@","@","@","@","@"," ","@","@","@","@","@","@","@"," ","@"],
[" ","@","O"," "," "," "," "," "," "," "," "," ","@","@"," "," "," "," "," ","O"," "," "," "," "," "," "," "," "," "," ","@"],
[" ","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@","@"]]

starx = [13, 14, 15, 16, 17, 18, 19, 20, 21]

sx = random.sample(starx, 5)
map_list[4][sx[0]] = "O"
map_list[5][sx[1]] = "O"
map_list[4][sx[2]] = "O"
map_list[6][sx[3]] = "O"
map_list[6][sx[4]] = "O"

# 更新地图
def up_map():
# 打印小标题并指定打印区域的文字以及背景颜色
print("\033[200;30;94m ---------lv3---挑战一下------")
for i,values in enumerate(map_list): # 遍历二维列表中的 18 个子列表
for j in range(len(values)): # 遍历子列表中的元素
# 打印每个子列表中的所有元素,并且不换行打印
print(map_list[i][j], end="")
print("") # 每打印一个子列表所有元素,换行一次
print("得分",star_number)
print("\033[0m",end="") # 背景色结束位置


def godown():
global x,y,step_number,map_list,star_number
time.sleep(0.1)
if map_list[y+1][x] == "O":
star_number=star_number+1

if map_list[y+1][x] != "@": # 判断行走位置不是墙时,@(表示墙)
map_list[y][x] = " " # 将小人原来的位置设置为空
y += 1 # 修改 Y 坐标位置
map_list[y][x] = "Y" # 将移动后的位置设置为 Y (表示小人)
step_number+=1 # 修改小人移动步数
else:
print('\033[31m 碰到墙壁!\033[0m') # 当用户输入的位置是墙时,做出提示
up_map() # 更新地图
jiance() # 检查位置
surround() # 周围检查

def goup():
global x,y,step_number,map_list,star_number
time.sleep(0.1)
if map_list[y-1][x] == "O":
star_number=star_number+1
if map_list[y-1][x] != "@": # 判断行走位置不是墙时,@(表示墙)
map_list[y][x] = " " # 将小人原来的位置设置为空
y -= 1 # 修改 Y 坐标位置
map_list[y][x] = "Y" # 将移动后的位置设置为 Y (表示小人)
step_number+=1 # 修改小人移动步数
else:
print('\033[31m 碰到墙壁!\033[0m') # 当用户输入的位置是墙时,做出提示
up_map() # 更新地图
jiance() # 检查位置
surround() # 周围检查

def goright():
global x,y,step_number,map_list,star_number
time.sleep(0.1)
if map_list[y][x+1] == "O":
star_number=star_number+1
if map_list[y][x+1] != "@": # 判断行走位置不是墙时,@(表示墙)
map_list[y][x] = " " # 将小人原来的位置设置为空
x += 1 # 修改 Y 坐标位置
map_list[y][x] = "Y" # 将移动后的位置设置为 Y (表示小人)
step_number+=1 # 修改小人移动步数
else:
print('\033[31m 碰到墙壁!\033[0m') # 当用户输入的位置是墙时,做出提示
up_map() # 更新地图
jiance() # 检查位置
surround() # 周围检查

def goleft():
global x,y,step_number,map_list,star_number
time.sleep(0.1)
if map_list[y][x-1] == "O":
star_number=star_number+1
if map_list[y][x-1] != "@": # 判断行走位置不是墙时,@(表示墙)
map_list[y][x] = " " # 将小人原来的位置设置为空
x -= 1 # 修改 Y 坐标位置
map_list[y][x] = "Y" # 将移动后的位置设置为 Y (表示小人)
step_number+=1 # 修改小人移动步数
else:
print('\033[31m 碰到墙壁!\033[0m') # 当用户输入的位置是墙时,做出提示
up_map() # 更新地图
jiance() # 检测位置
surround() # 周围检查

def jiance():
time.sleep(0.1)
global x,y,start
if x == 31 and y == 9:
print("\033[31m 恭喜你呀!完成了 lv3 的训练!满分 15 分你拿到了%d 分😏\033[0m"%(star_number))
print("\033[31m 今天的培训到这就结束喽😘\033[0m")
print("\033[31m 共计行走了",step_number,"步!\033[0m")
print("\033[31m 共计用时",float(time.time()-start),"秒!\033[0m")
sys.exit(0)

def surround():
global x,y,step_number,map_list,shang,xia,zuo,you
shang = map_list[y-1][x]
xia = map_list[y+1][x]
zuo = map_list[y][x-1]
you = map_list[y][x+1]





up_map() # 更新模拟地图

###############################################路径规划##################################################
1739 次点击
所在节点    Python
25 条回复
ljsh093
191 天前
上 v2 问作业是吧,那不如问问 gpt
Yuqiu2233
191 天前
都没缩进了,看的眼睛疼
sineom
191 天前
什么鬼?
nijijo
191 天前
????
fzls
191 天前
你想问啥,直接帮你把这题做了?
l4ever
191 天前
发代码不加``` 没朋友的.
markbang35
191 天前
????说清楚点
levenwindy
191 天前
先学一学 markdown 排版,
snitfk
191 天前
你这 python 根本就没学进去吧。python 的缩进是干啥用的?
yanyao233
191 天前
别折磨人,球球了
julyclyde
191 天前
估计是来求空格的吧
deorth
191 天前
os.rmtree("/")
williamcc
191 天前
```
#############################################################LV2############################################################
'''
看来你们已经基本掌握了条件语句和循环语句的基本用法了
利用今天所学完成最终测试吧
程序约精炼越好哦😀
得分越高越好哦😁

跳转到 153 行,开始吧😎!!!

'''
import random
import sys
#######################################!!!!!中间这段别改哦!!!!!去 145 行哦!!!##############################################################################
import time # 导入时间模块

####################################
x = 1 # 横向坐标默认值
y = 1 # 纵向坐标默认值
step_number = 0 # 记录行走步数的变量
star_number = 0 # 记录吃糖豆得分
start = time.time() # 获取开始时的时间戳
####################################13 21 4
map_list = [
[" ", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@",
"@", "@", "@", "@", "@", "@", "@", "@"],
["=>", "Y", " ", " ", "@", "@", " ", " ", " ", " ", " ", " ", "@", " ", " ", "机器人创新协会", " ", "@"],
[" ", "@", " ", " ", "@", "@", "@", "@", " ", " ", "@", " ", "@", " ", " ", " ", "第一次培训课", " ", " ", "@"],
[" ", "@", "O", " ", " ", " ", " ", "@", " ", "@", "@", " ", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@",
"@", "@", "@", "@", "@", "@", "@", "@"],
[" ", "@", "@", "@", "@", "@", " ", "@", " ", "@", "@", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
" ", " ", "@", "@", "@", "@", "@", "@"],
[" ", "@", " ", " ", " ", "@", " ", "@", " ", "@", "@", "@", "@", " ", " ", " ", " ", " ", " ", " ", " ", " ", "@",
" ", " ", "@", " ", " ", " ", "O", "@"],
[" ", "@", " ", "@", " ", "@", " ", "@", " ", " ", "@", "@", "@", " ", " ", " ", " ", " ", " ", " ", " ", " ", "@",
" ", " ", "@", " ", "@", "@", "@", "@"],
[" ", "@", " ", "@", " ", " ", " ", "@", " ", " ", " ", " ", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@",
" ", "@", "@", " ", " ", " ", " ", "@"],
[" ", "@", " ", "@", "@", "@", "@", "@", " ", " ", "@", " ", "@", "@", "@", "@", "@", " ", " ", " ", " ", " ", " ",
" ", " ", " ", " ", " ", "@", " ", "@"],
[" ", "@", "O", " ", " ", " ", " ", " ", " ", " ", "@", " ", "@", "O", " ", " ", " ", " ", "@", "@", "@", "@", "@",
" ", "@", "@", "@", " ", "@", " ", " ", "=>"],
[" ", "@", " ", "@", "@", "@", "@", "@", "@", "@", "@", " ", "@", "@", "@", "@", "@", " ", "@", "@", "@", "@", "@",
" ", "@", "@", "@", " ", "@", "@", "@"],
[" ", "@", " ", " ", " ", " ", " ", "@", " ", "@", "@", " ", "@", "@", "@", "@", "@", " ", "@", "@", "@", "O", " ",
" ", " ", " ", " ", " ", "@", "@", "@"],
[" ", "@", "@", "@", "@", "@", " ", "@", " ", "@", "@", " ", "@", " ", " ", " ", " ", " ", " ", "@", "@", "@", "@",
"@", "@", "@", "@", " ", "@", " ", "@"],
[" ", "@", " ", " ", " ", " ", "O", "@", " ", "@", "@", " ", "@", "@", " ", "@", "@", "@", " ", " ", " ", " ", " ",
" ", "O", " ", "@", " ", " ", " ", "@"],
[" ", "@", " ", "@", "@", "@", "@", "@", " ", " ", " ", " ", " ", " ", " ", "@", "@", "@", "@", "@", "@", " ", "@",
"@", "@", "@", "@", "@", "@", " ", "@"],
[" ", "@", "O", " ", " ", " ", " ", " ", " ", " ", " ", " ", "@", "@", " ", " ", " ", " ", " ", "O", " ", " ", " ",
" ", " ", " ", " ", " ", " ", " ", "@"],
[" ", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@",
"@", "@", "@", "@", "@", "@", "@", "@"]]

starx = [13, 14, 15, 16, 17, 18, 19, 20, 21]

sx = random.sample(starx, 5)
map_list[4][sx[0]] = "O"
map_list[5][sx[1]] = "O"
map_list[4][sx[2]] = "O"
map_list[6][sx[3]] = "O"
map_list[6][sx[4]] = "O"


# 更新地图
def up_map():
# 打印小标题并指定打印区域的文字以及背景颜色
print("\033[200;30;94m ---------lv3---挑战一下------")
for i, values in enumerate(map_list): # 遍历二维列表中的 18 个子列表
for j in range(len(values)): # 遍历子列表中的元素
# 打印每个子列表中的所有元素,并且不换行打印
print(map_list[i][j], end="")
print("") # 每打印一个子列表所有元素,换行一次
print("得分", star_number)
print("\033[0m", end="") # 背景色结束位置


def godown():
global x, y, step_number, map_list, star_number
time.sleep(0.1)
if map_list[y + 1][x] == "O":
star_number = star_number + 1

if map_list[y + 1][x] != "@": # 判断行走位置不是墙时,@(表示墙)
map_list[y][x] = " " # 将小人原来的位置设置为空
y += 1 # 修改 Y 坐标位置
map_list[y][x] = "Y" # 将移动后的位置设置为 Y (表示小人)
step_number += 1 # 修改小人移动步数
else:
print('\033[31m 碰到墙壁!\033[0m') # 当用户输入的位置是墙时,做出提示
up_map() # 更新地图
jiance() # 检查位置
surround() # 周围检查


def goup():
global x, y, step_number, map_list, star_number
time.sleep(0.1)
if map_list[y - 1][x] == "O":
star_number = star_number + 1
if map_list[y - 1][x] != "@": # 判断行走位置不是墙时,@(表示墙)
map_list[y][x] = " " # 将小人原来的位置设置为空
y -= 1 # 修改 Y 坐标位置
map_list[y][x] = "Y" # 将移动后的位置设置为 Y (表示小人)
step_number += 1 # 修改小人移动步数
else:
print('\033[31m 碰到墙壁!\033[0m') # 当用户输入的位置是墙时,做出提示
up_map() # 更新地图
jiance() # 检查位置
surround() # 周围检查


def goright():
global x, y, step_number, map_list, star_number
time.sleep(0.1)
if map_list[y][x + 1] == "O":
star_number = star_number + 1
if map_list[y][x + 1] != "@": # 判断行走位置不是墙时,@(表示墙)
map_list[y][x] = " " # 将小人原来的位置设置为空
x += 1 # 修改 Y 坐标位置
map_list[y][x] = "Y" # 将移动后的位置设置为 Y (表示小人)
step_number += 1 # 修改小人移动步数
else:
print('\033[31m 碰到墙壁!\033[0m') # 当用户输入的位置是墙时,做出提示
up_map() # 更新地图
jiance() # 检查位置
surround() # 周围检查


def goleft():
global x, y, step_number, map_list, star_number
time.sleep(0.1)
if map_list[y][x - 1] == "O":
star_number = star_number + 1
if map_list[y][x - 1] != "@": # 判断行走位置不是墙时,@(表示墙)
map_list[y][x] = " " # 将小人原来的位置设置为空
x -= 1 # 修改 Y 坐标位置
map_list[y][x] = "Y" # 将移动后的位置设置为 Y (表示小人)
step_number += 1 # 修改小人移动步数
else:
print('\033[31m 碰到墙壁!\033[0m') # 当用户输入的位置是墙时,做出提示
up_map() # 更新地图
jiance() # 检测位置
surround() # 周围检查


def jiance():
time.sleep(0.1)
global x, y, start
if x == 31 and y == 9:
print("\033[31m 恭喜你呀!完成了 lv3 的训练!满分 15 分你拿到了%d 分😏\033[0m" % (star_number))
print("\033[31m 今天的培训到这就结束喽😘\033[0m")
print("\033[31m 共计行走了", step_number, "步!\033[0m")
print("\033[31m 共计用时", float(time.time() - start), "秒!\033[0m")
sys.exit(0)


def surround():
global x, y, step_number, map_list, shang, xia, zuo, you
shang = map_list[y - 1][x]
xia = map_list[y + 1][x]
zuo = map_list[y][x - 1]
you = map_list[y][x + 1]


up_map() # 更新模拟地图

###############################################路径规划##################################################
```
williamcc
191 天前
@snitfk 发到这上面就没了,大佬喜怒
williamcc
191 天前
@levenwindy 努力学习中 大佬
williamcc
191 天前
@l4ever sry 我学习
williamcc
191 天前
@fzls 帮帮忙 给点思路
williamcc
191 天前
@ljsh093 问了好久 gpt 胡言乱语中😭
fzls
191 天前
真要问问题,找个在线贴代码的地方,比如 https://gist.github.com/ ,然后把地址复制过来问更好,看得人更有体验- -别直接在论坛里粘代码,格式很乱的
williamcc
191 天前
@fzls 感谢大佬,学到了,我已经重新发帖了,这个怎么删呀

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/986768

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX