Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. import random
  2.  
  3. diamondDurability = 1562
  4.  
  5. def checkBreak (level):
  6.     formula = int((100 / (level + 1)))
  7.     roll = random.randint(0, 100)
  8.  
  9.     if roll <= formula:
  10.         # Lost Durability        
  11.         return True
  12.     elif roll > formula:
  13.         # Kept Durability
  14.         return False
  15.  
  16.  
  17.  
  18. pickaxes = int(input("How many pickaxes would you like to use? "))
  19. level = int(input("What level unbreaking do the pickaxes have? "))
  20.  
  21. pickaxeLifeSpan = []
  22. lowestDurability = 10000000
  23. highestDurability = 0
  24.  
  25. while pickaxes > 0:
  26.     tests = 0
  27.     durability = diamondDurability
  28.  
  29.     while durability > 0:
  30.         if checkBreak(level):
  31.             durability -= 1
  32.         tests += 1
  33.     pickaxeLifeSpan.append(tests)
  34.     print("Pickaxe broke after", tests, "blocks broken.")
  35.  
  36.     if tests > highestDurability:
  37.         highestDurability = tests
  38.     if tests < lowestDurability:
  39.         lowestDurability = tests
  40.  
  41.     pickaxes -= 1
  42.  
  43.  
  44. print("The average number of blocks broken needed to break a pickaxe is", (sum(pickaxeLifeSpan) // len(pickaxeLifeSpan)))
  45. print("The least lasting pickaxe lasted", lowestDurability, "blocks broken.")
  46. print("The longest lasting pickaxe lasted", highestDurability, "blocks broken.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement