分享几个python有趣代码 您所在的位置:网站首页 简单好玩的微信代码 分享几个python有趣代码

分享几个python有趣代码

2024-02-20 13:27| 来源: 网络整理| 查看: 265

 hello,朋友们 在每天敲代码感觉到疲惫的时候  我们就可以利用python 花费几分钟写一个简单的游戏  放松一下 

石头剪刀布 简单游戏

import random choices = ["石头", "布", "剪刀"] computer = random.choice(choices) game_player = False computer_score = 0 # 电脑的初始分数 player_score = 0 # 玩家的初始分数 while True: game_player = input("石头, 布 or 剪刀? \n").capitalize() # 判断玩家和电脑的选择 if game_player == computer: print("平局!\n") elif game_player == "石头": if computer == "布": print("你输了!", computer, "covers", game_player,'\n') computer_score += 1 else: print("你赢了!", game_player, "smashes", computer,'\n') player_score += 1 elif game_player == "布": if computer == "剪刀": print("你输了!", computer, "cut", game_player,'\n') computer_score += 1 else: print("你赢了!", game_player, "covers", computer,'\n') player_score += 1 elif game_player == "剪刀": if computer == "石头": print("你输了", computer, "smashes", game_player,'\n') computer_score += 1 else: print("你赢了✌️!", game_player, "cut", computer,'\n') player_score += 1 elif game_player == '结束': print("——————最终得分——————") print(f"电脑:{computer_score}") print(f"玩家:{player_score}") break else: print("输入有误,请检查输入!") computer = random.choice(choices)

 故事大闯关

故事很短  虽然结局都是一样的  额 。。。 但是你们也可以自己改一下结局的啦 

import time user_name = str(input('请输入玩家姓名:')) print(f'{user_name}被困在森林里,你的任务是生存三天等待救援or自己逃出去。。。') time.sleep(1) select_a = input('你选择怎么做呢??? 1.等待救援;2.自己逃生\n') if int(select_a) == 1: time.sleep(1) print('你的首要任务是先找到一个睡觉的地方,加油!!!') time.sleep(3) select1 = input('在寻找的途中,你遇见了一只棕熊,你选择? 3.逃跑... 4.爬树待一会儿;5.其它\n') if int(select1) == 3: print('恭喜你 牺牲了...') elif int(select1) == 4: print('啊哦,你不会爬树呢亲亲,掉下来牺牲啦,撒花!!!') elif int(select1) == 5: print('哼!!1 不知天高地厚的臭小子 game over') else: time.sleep(3) print('你是个路痴呢,嘿嘿,只能等待救援啦') time.sleep(1) print('在等待的途中,睡着被冻死了')

 好啦 先浅浅分享两个吧  相信小伙伴们都会写 

然后希望在每天敲代码的时候注意自己的身体 要劳逸结合 然后祝每个看到这个的陌生人 或者是熟人 每天都开心 身体健康  拜!!



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有