Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. mport random
  2.  
  3. bingo_table = [
  4. [1, 2, 3, 4, 5],
  5. [6, 7, 8, 9, 10],
  6. [11, 12, 13, 14, 15],
  7. [16, 17, 18, 19, 20],
  8. [21, 22, 23, 24, 25]
  9. ]
  10.  
  11. def main():
  12. welcome_goodbye("Välkommen till Bingo!")
  13. while True:
  14. print_menu()
  15. user_choice = input("Val: ")
  16. if user_choice == "1":
  17. user_input = enter_number()
  18. random_list = random_ten()
  19. bingo_game(random_list)
  20. bingo_result(random_list, user_input)
  21. elif user_choice == "2":
  22. pass
  23. elif user_choice == "3":
  24. welcome_goodbye("God jul och gott nytt år!")
  25. break
  26. else:
  27. print("Vad god ange 1, 2 eller 3 som svar!")
  28.  
  29. def enter_number():
  30. while True:
  31.  
  32. user_input = input("Ange 5 siffror (mellan 1-25). Avgränsa med , : ").split(",")
  33. user_input = [int(i) for i in user_input]
  34.  
  35. if number_len_check(user_input) == True:
  36. if number_size_check(user_input) == True:
  37. if duplicate_check(user_input) == True:
  38. return user_input
  39. else:
  40. print("Du får inte skriva in dubbletter!")
  41. else:
  42. print("Var god skriv in siffror mellan 1-26!")
  43. else:
  44. print("Du får bara gissa på 5 siffror!")
  45.  
  46. def statistics():
  47. statistic_list = []
  48. statistics.append({"Spel 1":})
  49.  
  50.  
  51. def bingo_game(random_list):
  52. for row in bingo_table:
  53. for numbers in row:
  54. if numbers in random_list:
  55. print("[" + str(numbers), end="]")
  56. else:
  57. print(numbers, end=" ")
  58. print("")
  59.  
  60.  
  61. def bingo_result(random_list, user_input):
  62. result_list = []
  63. for numbers in user_input:
  64. if numbers in random_list:
  65. result_list.append(numbers)
  66. spacer()
  67. print("Antal rätt: " , len(result_list))
  68.  
  69.  
  70. def random_ten():
  71. return random.sample(range(1, 26), 10)
  72.  
  73.  
  74. def number_len_check(user_input):
  75. if len(user_input) == 5:
  76. return True
  77. else:
  78. return False
  79.  
  80. def number_size_check(user_input):
  81. for nr in user_input:
  82. if nr in range(1,26):
  83. pass
  84. else:
  85. return False
  86. return True
  87.  
  88. def duplicate_check(user_input):
  89. if len(user_input) == len(set(user_input)):
  90. return True
  91. else:
  92. return False
  93.  
  94.  
  95. def print_menu():
  96. print("1 | Spela Bingo")
  97. print("2 | Visa statestik")
  98. print("3 | Avsluta")
  99.  
  100.  
  101. def welcome_goodbye(prompt):
  102. print("═"*30)
  103. print(prompt)
  104. print("═"*30)
  105. return
  106.  
  107. def spacer():
  108. """En 'Spacer-funktion' som gör texten lättare att läsa med mindre kod"""
  109. print("═"*45)
  110.  
  111. main()
  112.  
  113. #För VG, namge spelare tex 1. Sedan gör texikon eller neslad lista.
  114. #lexikon med spelare som nycklar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement