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
  • 相关阅读:
    记: Spring Data Jpa @OneToMany 级联查询被动触发的问题
    后端小白的Bootstrap笔记
    最短路径问题
    深度优先搜索 & 广度优先搜索
    检讨书板子
    关于计时器
    博客园美化
    P4819 杀人游戏 (图论 )
    水站 (二分)
    对拍
  • 原文地址:https://www.cnblogs.com/two-peanuts/p/10032654.html
Copyright © 2011-2022 走看看