SHARE
TWEET

Uefa Predictor

makispaiktis Oct 23rd, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math
  2. import random
  3.  
  4. # The functions random.random() generates a number from 0.000000000 to 0.999999999 (from 0 inclusive to 1 exclusive)
  5. # If I want to generate a number from 0......100, I have to write
  6. # math.floor(random.random() * 101)
  7.  
  8. # 1. Introduction - Rules of the game
  9. print()
  10. print("**** WELCOME TO UEFA PREDICTOR PROGRAMME. You have to guess the score of a random match: Team A - Team B ****")
  11. print()
  12. print("1. If you guess the final winner/result of match (winner A, winner B or tie), you will get 3 points.")
  13. print("2. If you guess correctly the exact goals of one team (such as Team A), you will get 1 point.")
  14. print("3. If you have guessed correctly the final winner/result of the match AND you have also found correctly")
  15. print("the goal difference between the 2 teams, you will get 1 point.")
  16. print("So, if you guessed the EXACT SCORE of the match, you will get: 3 + (1 + 1) + 1 = 6 points")
  17. print()
  18. print()
  19.  
  20. # 2. Ask the user for the prediction - Check for invalid values in goals inputs
  21. print("Time for prediction. The match is between Team A and Team B. Write down separately how many goals you think the teams will score.")
  22. goalsA = int(input("Goals of Team A: "))
  23. while(goalsA <= 0):
  24.     goalsA = int(input("Goals of Team A: "))
  25. goalsB = int(input("Goals of Team B: "))
  26. while(goalsB <= 0):
  27.     goalsB = int(input("Goals of Team B: "))
  28.  
  29. # 3. Generate 2 numbers as the goals for the 2 teams
  30.     # 0: 0 will be created with 6/34 different ways (numbers )
  31.     # 1: 1 will be created with 10/34 different ways (numbers )
  32.     # 2: 2 will be created with 10/34 different ways (numbers )
  33.     # 3: 3 will be created with 4/34 different ways (numbers )
  34.     # 4: 4 will be created with 2/34 different ways (numbers )
  35.     # 5: 5 will be created with 1/34 different ways (numbers )
  36.     # 6: 6 will be created with 1/34 different ways (numbers )
  37. # In the end I will create a number which will be 0,1,2,3,4,5 or 6 but with different possibility
  38.  
  39. # Creating 2 indexes from 0 to 33 (range = 34 numbers)
  40. indexOfRealGoalsA = math.floor(random.random() * 34)
  41. indexOfRealGoalsB = math.floor(random.random() * 34)
  42. realGoalsA = -1000;
  43. realGoalsB = -1000;
  44.  
  45. # Create 2 if-statements to find how many goals has every team scored
  46.  
  47. # TEAM A
  48. if indexOfRealGoalsA >= 0 and indexOfRealGoalsA <=5:                            # 6 values
  49.     realGoalsA = 0
  50. elif indexOfRealGoalsA >= 6 and indexOfRealGoalsA <=15:                         # 10 values
  51.     realGoalsA = 1
  52. elif indexOfRealGoalsA >= 16 and indexOfRealGoalsA <=25:                        # 10 values
  53.     realGoalsA = 2
  54. elif indexOfRealGoalsA >= 26 and indexOfRealGoalsA <=29:                        # 4 values
  55.     realGoalsA = 3
  56. elif indexOfRealGoalsA == 30 or indexOfRealGoalsA == 31:                        # 2 values
  57.     realGoalsA = 4
  58. elif indexOfRealGoalsA == 32:                                                   # 1 value
  59.     realGoalsA = 5
  60. elif indexOfRealGoalsA == 33:                                                   # 1 value
  61.     realGoalsA = 6
  62.  
  63.  
  64. # TEAM B
  65. if indexOfRealGoalsB >= 0 and indexOfRealGoalsB <=5:                            # 6 values
  66.     realGoalsB = 0
  67. elif indexOfRealGoalsB >= 6 and indexOfRealGoalsB <=15:                         # 10 values
  68.     realGoalsB = 1
  69. elif indexOfRealGoalsB >= 16 and indexOfRealGoalsB <=25:                        # 10 values
  70.     realGoalsB = 2
  71. elif indexOfRealGoalsB >= 26 and indexOfRealGoalsB <=29:                        # 4 values
  72.     realGoalsB = 3
  73. elif indexOfRealGoalsB == 30 or indexOfRealGoalsB == 31:                        # 2 values
  74.     realGoalsB = 4
  75. elif indexOfRealGoalsB == 32:                                                   # 1 value
  76.     realGoalsB = 5
  77. elif indexOfRealGoalsB == 33:                                                   # 1 value
  78.     realGoalsB = 6
  79.  
  80.  
  81. # 4. Printing the final results between the 2 teams and the guesses also
  82. print()
  83. print()
  84. print("*************************************")
  85. print("Final Result: Team A - Team B : " + str(realGoalsA) + " - " + str(realGoalsB))
  86. print("You guessed:  Team A - Team B : " + str(goalsA) + " - " + str(goalsB))
  87. print("*************************************")
  88.  
  89.  
  90. # 5. Starting the process for giving points
  91. points = 0
  92.  
  93. # **********************************************************************************************************************
  94. # Start with **** RULE 2 ****
  95. foundGoalsA = False
  96. foundGoalsB = False
  97.  
  98. if goalsA == realGoalsA:
  99.     points += 1
  100.     foundGoalsA = True
  101. if goalsB == realGoalsB:
  102.     points += 1
  103.     foundGoalsB = True
  104. # **********************************************************************************************************************
  105. # Continue with **** RULE 1 ****
  106. result = -1000
  107. realResult = -1000
  108. foundResult = False
  109. # Results will take one of these 3 values:
  110.     # 1: Winner A
  111.     # 2: Winner B
  112.     # 0: Tie
  113.  
  114. # a) For the user's predictions
  115. if goalsA > goalsB:
  116.     result = 1
  117. elif goalsA < goalsB:
  118.     result = 2
  119. else:
  120.     result = 0
  121.  
  122. # b) For the final/real results
  123. if realGoalsA > realGoalsB:
  124.     realResult = 1
  125. elif realGoalsA < realGoalsB:
  126.     realResult = 2
  127. else:
  128.     realResult = 0
  129.  
  130. # Compare the 2 results
  131. if result == realResult:
  132.     points += 3
  133.     foundResult = True
  134.  
  135.  
  136. # **********************************************************************************************************************
  137. # Last rule is **** RULE 3 ****
  138. # Rule 3 precedes that user has found the result of the winner ---> foundResult == True
  139. foundGoalDifference = False
  140. if(foundResult):
  141.     if goalsA - goalsB == realGoalsA - realGoalsB:
  142.         points += 1
  143.         foundGoalDifference = True
  144.  
  145.  
  146. # **********************************************************************************************************************
  147. # **********************************************************************************************************************
  148. # **********************************************************************************************************************
  149. # **********************************************************************************************************************
  150. # Comparisons and calculations have stopped, it's time for displaying the user's points
  151. print()
  152. print("You got " + str(points) + " points!")
  153. if(foundResult):
  154.     print("Took +3 for guessing correctly the final winner/result of the match")
  155. if(foundGoalsA):
  156.     print("Took +1 for guessing correctly the goals from Team A")
  157. if(foundGoalsB):
  158.     print("Took +1 for guessing correctly the goals from Team B")
  159. if(foundGoalDifference):
  160.     print("Took +1 for guessing correctly the goal difference between the 2 teams")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top