当前位置: 首页>>代码示例>>Python>>正文


Python Die.getFaceValue方法代码示例

本文整理汇总了Python中die.Die.getFaceValue方法的典型用法代码示例。如果您正苦于以下问题:Python Die.getFaceValue方法的具体用法?Python Die.getFaceValue怎么用?Python Die.getFaceValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在die.Die的用法示例。


在下文中一共展示了Die.getFaceValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from die import Die [as 别名]
# 或者: from die.Die import getFaceValue [as 别名]
def main():
    theDie = Die()

    count = eval(input("How many times should I roll the die? "))

    c1 = 0
    c2 = 0
    c3 = 0
    c4 = 0
    c5 = 0
    c6 = 0

    for i in range(count):
        theDie.roll()
        val = theDie.getFaceValue()
        if val == 1:
            c1 = c1 + 1
        elif val == 2:
            c2 = c2 + 1
        elif val == 3:
            c3 = c3 + 1
        elif val == 4:
            c4 = c4 + 1
        elif val == 5:
            c5 = c5 + 1
        elif val == 6:
            c6 = c6 + 1
        else:
            print ("Error - value of die was", val)

    c1Percent = float(c1)/count * 100
    c2Percent = float(c2)/count * 100
    c3Percent = float(c3)/count * 100
    c4Percent = float(c4)/count * 100
    c5Percent = float(c5)/count * 100
    c6Percent = float(c6)/count * 100

    print ("Value 1 came up:", c1, "or a percentage of", c1Percent)
    print ("Value 2 came up:", c2, "or a percentage of", c2Percent)
    print ("Value 3 came up:", c3, "or a percentage of", c3Percent)
    print ("Value 4 came up:", c4, "or a percentage of", c4Percent)
    print ("Value 5 came up:", c5, "or a percentage of", c5Percent)
    print ("Value 6 came up:", c6, "or a percentage of", c6Percent)
开发者ID:jbhennes,项目名称:CSCI-220-Programming-1,代码行数:45,代码来源:rollAndCountDie.py

示例2: main

# 需要导入模块: from die import Die [as 别名]
# 或者: from die.Die import getFaceValue [as 别名]
def main():
   trisha = Die(-5)
##   trisha.roll()
   print("Trisha", trisha.getFaceValue())
   print(trisha)
##   sheldon = Die()
##   for i in range(10):
##      trisha.roll()
##      sheldon.roll()
##      tValue = trisha.getFaceValue()
##      sValue = sheldon.getFaceValue()
##      if sValue <= tValue:
##         sheldon.setFaceValue(5.5)
##         sValue = sheldon.getFaceValue()
##      print("Trisha: " + str(tValue), end = " ")
##      print("Sheldon: " + str(sValue))
##      if tValue > sValue:
##         print ("Trisha won!")
##      elif tValue == sValue:
##         print("Tie")
##      else:
##         print("Sheldon won!")
   print ("Done!")
开发者ID:jbhennes,项目名称:CSCI-220-Programming-1,代码行数:25,代码来源:dieTest.py


注:本文中的die.Die.getFaceValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。