Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- print("****************************************************************************************************")
- print("****************************************************************************************************")
- # 1. Intro
- length = 20 # The SIZE of the ANSWER
- iterations = 10 # Poses fores tha ginei epanalipsi tou idiou senariou gia na exw sygkentrwtika apotelesmata (10000 poly kali proseggisi)
- print("Imagine you are given a test WITH 20 QUESTIONS (True or False), but you don't know ANY answer to them.")
- print("So, you decide to give your answers in a random way. You reply true or false RANDOMLY.")
- print()
- print("So, you have to write down in a row a string (with length = 20) of 'T' or 'F' like this one: TTFFTFTFTFFFTTFFTTFT:")
- answer = input("Write down your answer: ")
- while len(answer) != length:
- print("You gave me a string made of " + str(len(answer)) + " letters and not " + str(length) + " letters")
- answer = input("Write down your answer: ")
- print()
- #### Iterations #### Apla kanw ena for pou tha trexei to idio senario kapoies fores gia na min kanw synexeia terminate programme
- correctLettersInAllIterations = 0
- for epanalipsi in range(iterations):
- print("Simulation no" + str(epanalipsi + 1) + ": ")
- # 2. The computer creates its RANDOM answer and then its gonna be a comparison betwwen the 2 answers
- PCAnswer = []
- for i in range(length):
- r = random.randint(0, 1)
- if r == 0:
- PCAnswer.append('F') # If the generated number is 0 ---> I append the letter 'F' in the PCAnswer
- else:
- PCAnswer.append('T')
- # 3. Convert the user's answer in upperCase for safety
- answer = answer.upper()
- # 4. Compare the 2 answers (remember that answer = string and PCAnswer = list)
- correctLetters = 0
- for i in range(length):
- if answer[i] == PCAnswer[i]:
- correctLetters += 1
- print("******************************************")
- correctLettersInAllIterations += correctLetters
- print("Your answer: " + answer)
- print("PC's answer: " + ''.join(map(str, PCAnswer)))
- print("PC found " + str(correctLetters) + "/" + str(length) + " answers.")
- print()
- print("**************")
- print("Average correct letters: " + str(correctLettersInAllIterations/iterations))
- print("**************")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement