fork(1) download
  1. def depth_charge(g):
  2. from random import randint, seed
  3. from math import log
  4. print "DEPTH CHARGE GAME"; print
  5. n = int(log(g)/log(2))+1; seed()
  6. play_again = "Y"
  7. print "YOU ARE CAPTAIN OF THE DESTROYER USS DIGITAL."
  8. print "AN ENEMY SUB HAS BEEN CAUSING YOU TROUBLE. YOUR"
  9. print "MISSION IS TO DESTROY IT. YOU HAVE", n, "SHOTS."
  10. print "SPECIFY DEPTH CHARGE EXPLOSION POINT WITH A"
  11. print "TRIO OF NUMBERS -- THE FIRST TWO ARE THE"
  12. print "SURFACE COORDINATES; THE THIRD IS THE DEPTH."
  13. while play_again == "Y":
  14. print; print "GOOD LUCK !"; print
  15. a, b, c = randint(1,g), randint(1,g), randint(1,g)
  16. found_it = False
  17. for d in range(1,n+1):
  18. if not found_it:
  19. x, y, z = input("TRIAL # " + str(d) + " ? ")
  20. if a == int(x) and b == int(y) and c == int(z):
  21. print "B O O M ! ! YOU FOUND IT IN", d, "TRIES!"
  22. found_it = True
  23. else:
  24. print "SONAR REPORTS SHOT WAS",
  25. if b < y: print "NORTH",
  26. if y < b: print "SOUTH",
  27. if a < x: print "EAST",
  28. if x < a: print "WEST",
  29. if y <> b or x <> a: print "AND",
  30. if c < z: print "TOO LOW."
  31. if z < c: print "TOO HIGH."
  32. if c == z: print "DEPTH OK."
  33. if not found_it:
  34. print "YOU HAVE BEEN TORPEDOED! ABANDON SHIP!"
  35. print "THE SUBMARINE WAS AT", a, b, c
  36. print; print; play_again = raw_input("ANOTHER GAME (Y OR N) ? ")
  37. print "OK. HOPE YOU ENJOYED YOURSELF."
Success #stdin #stdout 0.01s 8968KB
stdin
Standard input is empty
stdout
Standard output is empty