一、游戏1、2、3

print("-------------- Guess Number Game---------------------")
num=input("Guess Number")
guess = int(num)
print(guess)
if guess == 6:
print("true")
else:
if guess >6:
print("大了")
else:
print("小了")
print("Game Over!Thanks。")
print("-------------- Guess Number Game---------------------")
num=input("Guess Number")
guess = int(num)
if guess ==6:
print("true")
else:
while guess !=6:
if guess == 6:
print("true")
else:
if guess >6:
print("大了")
else:
print("小了")
number= input("false,Guess Again")
guess = int(number)
if guess ==6:
print("true")
print("Game Over!Thanks。")
import random
secret =random.randint(1,10)
print("-------------- Guess Number Game---------------------")
num=input("Guess Number")
guess = int(num)
if guess == secret:
print("true")
else:
while guess !=secret:
if guess == secret:
print("true")
else:
if guess >secret:
print("大了")
else:
print("小了")
number= input("false,Guess Again")
guess = int(number)
if guess ==secret:
print("true")
print("Game Over!Thanks。")

二、打印乘法表、冒泡排序

# 打印乘法表
for x in range(1,10):
for y in range(1,10):
if y <=x:
print(("%d * %d = %d"%(y,x,x*y)+"\t"),end="")
print() # 1 * 1 = 1
# 1 * 2 = 2 2 * 2 = 4
# 1 * 3 = 3 2 * 3 = 6 3 * 3 = 9
# 1 * 4 = 4 2 * 4 = 8 3 * 4 = 12 4 * 4 = 16
# 1 * 5 = 5 2 * 5 = 10 3 * 5 = 15 4 * 5 = 20 5 * 5 = 25
# 1 * 6 = 6 2 * 6 = 12 3 * 6 = 18 4 * 6 = 24 5 * 6 = 30 6 * 6 = 36
# 1 * 7 = 7 2 * 7 = 14 3 * 7 = 21 4 * 7 = 28 5 * 7 = 35 6 * 7 = 42 7 * 7 = 49
# 1 * 8 = 8 2 * 8 = 16 3 * 8 = 24 4 * 8 = 32 5 * 8 = 40 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64
# 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81 #冒泡排序
import random
lis=[x for x in range(10)]
random.shuffle(lis)
print(lis) # [2, 5, 0, 6, 4, 3, 7, 8, 1, 9] for x in range(9):
for y in range(9): # for y in range(len(lis)-1-x): python的冒泡排序
if lis[y] >lis[y+1]: lis[y],lis[y+1]=lis[y+1],lis[y] print(lis) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

三、点将台游戏

点将台.py

import 点将小助手 as dj
while True:
dj.show_menu()
user_action = input('请输入你想要的操作')
if user_action in ['','','','']:
if user_action =='':
dj.add_stu()
elif user_action =='':
dj.show_all()
elif user_action =='':
dj.query_stu()
elif user_action =='':
break
else:
print('你输入的操作有误请重新选择')

点将小助手.py

lis_stu = []
dic = {'name':'姓名','age':'年龄','clazz':'学科'} def add_stu():
print('这是一个新增操作')
dic = {}
dic['name'] = input('请输入姓名')
dic['age'] = input('请输入年龄')
dic['clazz'] = input('请输入学科')
lis_stu.append(dic) def show_all():
print('显示全部')
if len(lis_stu):
print("\t%(name)s\t\t%(age)s\t\t%(clazz)s" % dic)
for item in lis_stu:
print("\t%(name)s\t\t%(age)s\t\t%(clazz)s"%item)
else:
print('请先注册信息') def query_stu():
print('查询方法')
name_item= input('请输入要查询的武将姓名') for x in lis_stu:
if x['name'] == name_item:
print("\t%(name)s\t\t%(age)s\t\t%(clazz)s"%x)
user_input= input('请输入你想要的操作 1删除 2修改 3返回')
if user_input in ['','','']:
if user_input =='':
lis_stu.remove(x)
elif user_input == '':
x['name'] = my_input('请输入姓名',x['name'])
x['age'] = my_input('请输入年龄',x['age'])
x['clazz'] = my_input('请输入学科',x['clazz'])
elif user_input == '':
break
break
else:
print('没有你要的武将') def my_input(mess,dic_val):
user_in = input(mess)
if len(user_in):
return user_in
else:
return dic_val def show_menu():
print('=' * 50)
print('''
1.武将招募
2.部队集合
3.武将查询
0.退朝
''')
print('=' * 50)

Python demo working的更多相关文章

  1. CentOS thrift python demo

    编辑接口文件 hellowworld.thrift service HelloWorld { string ping(), string say(1:string msg) } 编辑 server.p ...

  2. python demo整理

    1 变量作用域 #!/usr/bin/python # coding=utf-8 name = "whole global name" class Person: name = & ...

  3. appium python demo

    #coding=utf-8from appium import webdriverdesired_caps={}desired_caps["platformName"]=" ...

  4. rabbitmq python demo 参考链接地址

    链接地址: https://docs.openstack.org/oslo.messaging/latest/reference/server.html https://www.cnblogs.com ...

  5. appium+Python真机运行测试demo的方法

    appium+Python真机运行测试demo的方法 一,    打开手机的USB调试模式 二,    连接手机到电脑 将手机用数据线连接到电脑,并授权USB调试模式.查看连接的效果,在cmd下运行命 ...

  6. 第一个 Python 程序 - Email Manager Demo

    看了一些基础的 Python 新手教程后,深深感觉到 Python 的简洁与强大,这是我的第一个 Python Demo.下面是完整代码与执行截图. 代码: # encoding: utf-8 ''' ...

  7. pyhanlp python 脚本的demo补充

    java demo https://github.com/hankcs/HanLP/tree/master/src/test/java/com/hankcs/demo github python de ...

  8. 【Python五篇慢慢弹(5)】类的继承案例解析,python相关知识延伸

    类的继承案例解析,python相关知识延伸 作者:白宁超 2016年10月10日22:36:57 摘要:继<快速上手学python>一文之后,笔者又将python官方文档认真学习下.官方给 ...

  9. Eclipse中Python开发环境搭建

    Eclipse中Python开发环境搭建  目 录  1.背景介绍 2.Python安装 3.插件PyDev安装 4.测试Demo演示 一.背景介绍 Eclipse是一款基于Java的可扩展开发平台. ...

随机推荐

  1. 使用vuex的流程随笔

    1.在建好的vue项目中新建一个vuex文件夹在此文件夹下建一个index.js文件,在此文件下引入vuex 模块(当然需要先npm下载)和vue模块,在引入你所有的自定义的module.js模块(下 ...

  2. hadoop-08-关闭THP服务

    hadoop-08-关闭THP服务 #查看THP服务cat /sys/kernel/mm/redhat_transparent_hugepage/enabledcat /sys/kernel/mm/r ...

  3. spark的内存分配管理

    SPARK的内存管理器 StaticMemoryManager,UnifiedMemoryManager 1.6以后默认是UnifiedMemoryManager. 这个内存管理器在sparkCont ...

  4. 2、Python列表和元组

    2.Python序列 序列是一种数据存储方式,类似于C语言的数组.简单的说序列是一块用来存储多个值的连续内存空间,同一个序列的元素通常是相关的. Python中常用的序列结构有列表.元组.字典.字符串 ...

  5. poj_3371

    一道模拟题,写的有点麻烦 #include<iostream> #include<cstring> #include<cstdio> #include<alg ...

  6. jsp中对话框的实现

    <Input type=submit name="g" style="font-size:20px" value="提交" oncli ...

  7. 如何让alertdialog选择完后自动关闭

    builder.setIcon(R.drawable.ic_system) .setTitle("串口号") .setSingleChoiceItems(mPorts, mSele ...

  8. 《剑指offer》栈的压入、弹出序列

    一.题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压 ...

  9. JTable表格案例

    package com.szht.gpy.frame; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import ...

  10. centos7 安装 Python netsnmp模块

    由于模块的安装过程中有点艰难(其实挺简单,只是参照网上的教程很多都装不成功,花了很多时间...),所以记下来备忘. 先装一下python-devel 模块,执行命令 yum install pytho ...