zoukankan      html  css  js  c++  java
  • Python初学者随笔(一)_ 用Python写的第一个游戏“猜数字”

    如标题所写,这篇随笔主要记录下学习Python过程中用Python写的第一个游戏——“猜数字”_跟着“小甲鱼”学Python,链接: https://b23.tv/BV1c4411e77t

     1 # -*- coding: cp936 -*-
     2 """用Python设计第一个游戏"""
     3 import random
     4 count = 3
     5 answer = random.randint(1,10)
     6 while count > 0:
     7     temp = input("请输入一个数字:")
     8     guess = int(temp)
     9     if guess == answer:
    10         print("猜对了")
    11         break
    12     else:
    13         if guess < answer:
    14             print("小啦")
    15         else:
    16             print("大啦")
    17     count = count - 1
    18 print("游戏结束")

    至此,第一个使用Python写的程序代码结束。

    ---------------------------------------------------------------

    下面是一些笔记

    首先,最重要的是Python要求严格的对齐与缩进。用以区分语句的块

    其次第3行

    import random

    是使用

    import

    插入“random”模块,“random”模块的作用是产生(伪)随机数

    语法为:

    import random
    random.randint(1,10) #(1,10)是产生随机数的范围

    记录于200706

  • 相关阅读:
    TCP和UDP区别
    session和cookie的区别
    2019 腾讯正式批笔试题题解
    modCount干嘛的
    分布式系统唯一ID生成方案汇总
    分布式数据库名词
    快手第一题
    南柯一梦
    349. 两个数组的交集
    synchronized锁优化
  • 原文地址:https://www.cnblogs.com/jsleepc/p/13256433.html
Copyright © 2011-2022 走看看