zoukankan      html  css  js  c++  java
  • 小甲鱼-002用python设计第一个游戏

    第一个游戏

    示例1:

    #/usr/bin/env python3
    # -*-coding:utf-8 -*-
    print("-----我是自恋狂-----")
    temp = input("请问骰子有几个面:")
    guess = int(temp)
    if guess == 6:
        print("你猜对了")
    else:
        print("猜错了")
    print("游戏结束")
    

    示例2:

    为上例增加异常捕捉

    #/usr/bin/env python3
    # -*-coding:utf-8 -*-
    print("-----我是自恋狂-----")
    temp = input("请问骰子有几个面:")
    try:
        guess = int(temp)
        if guess == 6:
            print("你猜对了")
        else:
            print("猜错了")
    except ValueError as e:
        print("你的输入值是:%s"%temp)
        print("此处要求输入纯数字,请重新运行")
    finally:
        print("游戏结束")
    

    内置函数

    内置函数为built in function,建成BIF。
    
    #/usr/bin/env python3
    # -*-coding:utf-8 -*-
    #BIF 内置函数,查看内置函数dir(__builtins),小写的是内置函数,通过help可以查看当前方法的使用
    print(dir(__builtins__))
    #查看方法介绍
    help(str)
    

    FAQ

    print使用 ‘+’连接,两边值的类型必须一致,否则会提示TypeError。

    #/usr/bin/env python3
    # -*-coding:utf-8 -*-
    a = 7
    print("'hello',a: ",'hello',a)
    print("'hello %s'%a: ",'hello %s'%a)
    # +号两边转为相同类型即可
    print("'hello '+str(a)",'hello '+str(a))
    
  • 相关阅读:
    Keras实例教程(2)
    Keras实例教程(1)
    tf.nn.l2_loss()的用法
    在tensorflow中使用batch normalization
    Tensorflow的LRN是怎么做的
    CNN卷积中多通道卷积的参数问题
    caffe学习网站
    交叉熵反向求导计算过程
    矩阵求导
    循环神经网络(RNN)模型与前向反向传播算法
  • 原文地址:https://www.cnblogs.com/csj2018/p/10061984.html
Copyright © 2011-2022 走看看