标签:注意 模块 dom 数据 变量 lis float avg NPU
模块导入:
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 |
标签:注意 模块 dom 数据 变量 lis float avg NPU
原文地址:https://www.cnblogs.com/two-peanuts/p/10032654.html