當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。