Advertisement
makispaiktis

20 True or False Questions

Apr 26th, 2019 (edited)
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.37 KB | None | 0 0
  1. import random
  2.  
  3. print("****************************************************************************************************")
  4. print("****************************************************************************************************")
  5.  
  6. # 1. Intro
  7. length = 20               # The SIZE of the ANSWER
  8. iterations = 10           # Poses fores tha ginei epanalipsi tou idiou senariou gia na exw sygkentrwtika apotelesmata (10000 poly kali proseggisi)
  9. print("Imagine you are given a test WITH 20 QUESTIONS (True or False), but you don't know ANY answer to them.")
  10. print("So, you decide to give your answers in a random way. You reply true or false RANDOMLY.")
  11. print()
  12. print("So, you have to write down in a row a string (with length = 20) of 'T' or 'F' like this one: TTFFTFTFTFFFTTFFTTFT:")
  13. answer = input("Write down your answer: ")
  14. while len(answer) != length:
  15.     print("You gave me a string made of " + str(len(answer)) + " letters and not " + str(length) + " letters")
  16.     answer = input("Write down your answer: ")
  17.  
  18. print()
  19. ####    Iterations    #### Apla kanw ena for pou tha trexei to idio senario kapoies fores gia na min kanw synexeia terminate programme
  20. correctLettersInAllIterations = 0
  21. for epanalipsi in range(iterations):
  22.     print("Simulation no" + str(epanalipsi + 1) + ": ")
  23.  
  24.     # 2. The computer creates its RANDOM answer and then its gonna be a comparison betwwen the 2 answers
  25.     PCAnswer = []
  26.     for i in range(length):
  27.         r = random.randint(0, 1)
  28.         if r == 0:
  29.             PCAnswer.append('F')                # If the generated number is 0 ---> I append the letter 'F' in the PCAnswer
  30.         else:
  31.             PCAnswer.append('T')
  32.  
  33.  
  34.     # 3. Convert the user's answer in upperCase for safety
  35.     answer = answer.upper()
  36.  
  37.  
  38.     # 4. Compare the 2 answers (remember that answer = string and PCAnswer = list)
  39.     correctLetters = 0
  40.     for i in range(length):
  41.         if answer[i] == PCAnswer[i]:
  42.             correctLetters += 1
  43.  
  44.     print("******************************************")
  45.     correctLettersInAllIterations += correctLetters
  46.     print("Your answer: " + answer)
  47.     print("PC's answer: " + ''.join(map(str, PCAnswer)))
  48.     print("PC found " + str(correctLetters) + "/" + str(length) + " answers.")
  49.     print()
  50.  
  51. print("**************")
  52. print("Average correct letters: " + str(correctLettersInAllIterations/iterations))
  53. print("**************")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement