zoukankan      html  css  js  c++  java
  • Python-模块,以及使用文本中的数据

    模块导入:

    from math import pi as math_pi

    print math_pi     #相当于把pi取了个别名

    # -*- coding: cp936 -*-
    from random import randint


    #读取文件中的数据
    f = file("game.txt")
    score = f.read().split()   #相当于放入score这个list里了


    #分别存入变量中
    game_times = int(score[0])
    min_times = int(score[1])
    total_times = int(score[2])


    #计算游戏的平均轮数,注意浮点数的运用
    if game_times > 0:
        #avg_times = total_times / game_times   注意此处这样写会出现什么后果
        avg_times = float(total_times) / game_times  #7/2=3
    else:
        avg_times = 0


    #输出成绩信息
    print("你已经玩了%d次,最少%d轮猜出答案,平均%.2f轮猜出答案") %(game_times,min_times,avg_times)
                                                 #%.2f的意思要注意


    num = randint(1,100)
    print "Guess what is the nember?"


    i = 6
    while i:
        answer = input()
        if answer < num:
            print("too small")
        else:
            print("too big")
        if answer == num:
            print("Yes, You are right!")
        i=i-1
  • 相关阅读:
    qt捕鱼达人
    linux通过源码安装gdb
    打造简易http服务器
    linux缓存同步
    NOI之后的碎碎念
    Validate至少有一个不能为空
    IOI 2020 集训队作业
    P6033 [NOIP2004 提高组] 合并果子 加强版 题解
    P3017 [USACO11MAR]Brownie Slicing G 题解
    LOJ #145. DFS 序 2 题解
  • 原文地址:https://www.cnblogs.com/two-peanuts/p/10032654.html
Copyright © 2011-2022 走看看