×
☰ Sebsnetwork

Human Test - Python - 6KB

                
                    #Tested Version of python:
                    #Python  3.7.9
                    #Python  3.9.13
                    #Python  3.10.7
                    
                    #Human test
                    
                    #Last Updated : 25/03/2023 - 23:48 pm
                    
                    #----------------------------------
                    #Imports
                    #----------------------------------
                    
                    import time
                    import datetime
                    from datetime import datetime
                    import os
                    import random
                    
                    #----------------------------------
                    #variables
                    #----------------------------------
                    
                    name = ''
                    ID = random.randint(1,10000000000) 
                    reaction_time = 0
                    memory_result = 0
                    mentalmaths_result = 0
                    
                    #----------------------------------
                    #clear the console
                    #----------------------------------
                    def clearConsole():
                        os.system('cls' if os.name=='nt' else 'clear') 
                    #----------------------------------
                    #All the def in the world!
                    #----------------------------------
                    def reaction():
                        clearConsole()
                        print("Welcome to the reaction time test!!")
                        print("Here we will test your wonderful reaction time:")
                        print("We will say randomly 'GO!!' and you will have to press the Enter Key as fast as possible.")
                        print("This will be done 3 times to get an average!")
                        print("Understood? (yes / no)")
                        answer = input("")
                        if answer == 'yes' or answer == 'ye'or answer == "yess":
                            clearConsole()
                            print("Okay then let's go!")
                            reaction_test()
                        else:
                            clearConsole()
                            print("Well tough your doing it!")
                            
                            reaction_test()
                    
                    def reaction_test():
                        global reaction_time
                        start = input("Press enter to begin:")
                        clearConsole()
                        timedone = 1
                        time_took = 0 
                        while timedone < 4:
                            clearConsole()
                            print(f"Attempt {timedone}\nPress enter when you see 'GO!!'")
                            time.sleep(random.randint(1,10))
                            start = time.time()
                            go = input("GO!!")
                            end = time.time()
                            time_elapsed = end - start
                            time_took = time_took + time_elapsed
                            timedone = timedone  + 1
                        time_took = time_took / 3
                        time_took = time_took * 1000
                        time_took = int(time_took)
                        reaction_time = time_took
                    
                    def memory():
                        clearConsole()
                        print("Welcome to memory test!!")
                        print("Here we will test your memeory on how much you can remeber:")
                        print("A number will pop up and you will have 2 seconds to memeorize it and then repeat it back when it disapears!")
                        print("This will be done until you get 1 wrong!")
                        start = input("Press Enter to continue")
                        memory_test()
                    
                    def memory_test():
                        global memory_result
                        clearConsole()
                        start = input("Once your ready just press Enter to start the test and a number will show up and dissapear after 2 seconds!")
                        going = 0
                        num1 = 1
                        num2 = 10
                        correct = 0
                        while going == 0:
                            number = random.randint(num1,num2)
                            print(number)
                            time.sleep(2)
                            clearConsole()
                            try:
                                answer = int(input("Repeat:"))
                            except:
                                break
                            if answer == number:
                                correct = correct + 1
                                clearConsole()
                                num1 *= 10
                                num2 *= 10
                            else:
                                going += 1
                        print(correct)
                        memory_result = correct
                    
                    
                    def mentalmaths():
                        clearConsole()
                        print("""Welcome to the Mental maths test!
                    Here we will test your mental maths:
                    Two numbers will appear and we will test how fast you can answer theses simple maths questions!
                    This will be done 3 times to get an average! 
                        """)
                        start = input("Press Enter to continue.")
                        mentalmaths_test()
                    
                    
                    def mentalmaths_test():
                        global mentalmaths_result
                        clearConsole()
                        start = input("Once your ready press Enter and answer the question when it appears as fast as possible.")
                        num1_l = [100, 10, 2, 1, 0]
                        num2_l = [10, 5, 3, 1, 0, 250]
                        enough = 1
                        time_elapsed = 0
                        while enough < 4:
                            num1 = random.choice(num1_l)
                            num2 = random.choice(num2_l)
                            answer = num1 * num2
                            clearConsole()
                            start_t = time.time()
                            request = int(input(f"{num1} x {num2} = "))
                            correct = 0
                            while correct == 0:
                                if request == answer:
                                    clearConsole()
                                    end_t = time.time()
                                    time_took = end_t - start_t
                                    time_elapsed = time_elapsed + time_took
                                    print("Well done!")
                                    correct = 1
                                    enough = enough + 1
                                    print(time_took)
                                    time_took = 0
                                    time.sleep(2)
                                else:
                                    clearConsole
                                    print("Try again")
                                    request = int(input(f"{num1} x {num2} = "))
                        print(time_elapsed)
                        time_elapsed = time_elapsed / 3
                        time_elapsed = time_elapsed * 1000
                    
                        time_elapsed = int(time_elapsed)
                        print(f"{time_elapsed}ms")
                        mentalmaths_result = time_elapsed
                        clearConsole()
                    #----------------------------------
                    #Beginning of actual code aka start
                    #----------------------------------
                    print("Welcome to the human test!")
                    start11 =input("\nPress Enter to begin!")
                    reaction()
                    memory()
                    mentalmaths()
                    name = input("Please enter your name: ")
                    clearConsole()
                    print(f"""Well Done you have done this amazing and short human test!!
                    Here are your results:
                    ----------
                    Name: {name}
                    ID: {ID}
                    Reaction time: {reaction_time}ms.
                    You can remember up to {memory_result} digits.
                    Takes an average of {mentalmaths_result}ms to answer simple mental maths questions.
                    ----------
                    """)
                    option = int(input("""What would you like to do:
                    1. Save this onto your computer to share & quit (.txt file)
                    2. Quit
                    Option: """))
                    if option == 1:
                        with open (f'{ID}_results.txt','w') as f:
                            f.write(f"----------\nName: {name}\nID: {ID}\nReaction time: {reaction_time}ms\nCan remember up to {memory_result} digits.\nTakes on average {mentalmaths_result}ms to answer simple mental maths questions\nDate: {datetime.now()}\n----------")
                    else:
                        print("Goodbye")
                        time.sleep(1)
                        quit()