|
| 1 | +import math |
| 2 | +import datetime |
| 3 | +import formatting |
| 4 | + |
| 5 | +def kSquareRoot(tested_num, repetitions): # KasCode's Square Root finder algorithm! |
| 6 | + current_min = 0 |
| 7 | + current_max = tested_num |
| 8 | + percent_done = 0 |
| 9 | + |
| 10 | + for loop_place in range(repetitions): |
| 11 | + middle = current_min + ( current_max - current_min ) / 2 |
| 12 | + #print("min: "+str(current_min)+", max: "+str(current_max)+", middle: "+str(middle)) |
| 13 | + |
| 14 | + tenth_percent = math.floor(loop_place/repetitions*10) |
| 15 | + if tenth_percent > percent_done: |
| 16 | + percent_done = tenth_percent |
| 17 | + print(str(tenth_percent*10)+"%") |
| 18 | + |
| 19 | + if middle * middle == tested_num: |
| 20 | + print("Exact result found after "+str(loop_place)+" repetitions!") |
| 21 | + break |
| 22 | + |
| 23 | + if middle * middle > tested_num: |
| 24 | + current_max = middle |
| 25 | + else: |
| 26 | + current_min = middle |
| 27 | + |
| 28 | + return current_min + ( current_max - current_min ) / 2 |
| 29 | + |
| 30 | +def sqrtcmd(): |
| 31 | + tested_num = 0 |
| 32 | + reps = 0 |
| 33 | + |
| 34 | + while True: |
| 35 | + try: |
| 36 | + tninput = input("Enter the number you want to find the square root of: ") |
| 37 | + tninput = int(tninput) |
| 38 | + except ValueError: |
| 39 | + print("Make sure you're typing in a number!") |
| 40 | + continue |
| 41 | + else: |
| 42 | + tested_num = tninput |
| 43 | + break |
| 44 | + |
| 45 | + while True: |
| 46 | + try: |
| 47 | + tninput = input("Now enter the number of algorithm repetitions. Type \"help\" for more: ") |
| 48 | + if tninput == "help": |
| 49 | + print("This number is how many times this algorithm will repeat. The higher the number, the more accurate my result will be! I recommend around 5000-50000000 (A lot)") |
| 50 | + continue |
| 51 | + else: |
| 52 | + tninput = int(tninput) |
| 53 | + except ValueError: |
| 54 | + print("Make sure you're typing in a number!") |
| 55 | + continue |
| 56 | + else: |
| 57 | + reps = tninput |
| 58 | + break |
| 59 | + |
| 60 | + result = kSquareRoot(tested_num, reps) |
| 61 | + print("Result: "+str(result)) |
| 62 | + |
| 63 | +def timecmd(): |
| 64 | + time = datetime.datetime.now() |
| 65 | + print("The time is " + time.strftime("%H") + ":" + time.strftime("%M")) |
| 66 | + print("Today is " + time.strftime("%A") + ", " + time.strftime("%d") + " " + time.strftime("%B")) |
| 67 | + |
| 68 | +def helpcmd(): |
| 69 | + print("\nI work by learning the answers to any question you have, then remembering them for later.\nFor more help, type in any of the subjects below for details.\nWhen you're done, type in \"exit\" to go back.") |
| 70 | + |
| 71 | + print("\nformat\ncommands\ninput markers\n") |
| 72 | + |
| 73 | + while True: |
| 74 | + user_input = input("[H] ") |
| 75 | + user_input = formatting.format_input(user_input) |
| 76 | + |
| 77 | + if user_input == "exit": |
| 78 | + break |
| 79 | + |
| 80 | + if user_input == "format": |
| 81 | + print("I recommend that you don't add any punctuations such as ! or ?. I also don't really care whether you capitalize your sentences or not!") |
| 82 | + continue |
| 83 | + |
| 84 | + if user_input == "commands": |
| 85 | + print("I have some built in commands that you can use such as time and math!") |
| 86 | + print("You start all commands with a \"/\" and then the command. Below is a list of all my commands") |
| 87 | + print("/math - [ALPHA] This is still in development, but right now this is capable of doing basic math with only two numbers.") |
| 88 | + print("/help - This sends you to this page!") |
| 89 | + print("/services - Lists down all the services being used in this program, and gives you the option to disable/enable them") |
| 90 | + print("/time - Prints the time and date! Pretty nifty, huh?") |
| 91 | + print("/sqrt - Brings up the kSquareRoot function for finding the square root of the number you're looking for.") |
| 92 | + continue |
| 93 | + |
| 94 | + if user_input == "input markers": |
| 95 | + print("You might have noticed that when you're typing something in, theres a little box on the left. Here is a list of what they mean:") |
| 96 | + print(" [~] - basic input where you write in a question") |
| 97 | + print(" [H] - help page input for detail on subjects") |
| 98 | + print(" [A] - answering input that will set whatever you write as the answer to your question") |
| 99 | + print(" [S] - service editing input") |
| 100 | + continue |
| 101 | + |
| 102 | +def mathcmd(): |
| 103 | + print("\nI work by learning the answers to any question you have, then remembering them for later.\nFor more help, type in any of the subjects below for details.\nWhen you're done, type in \"exit\" to go back.") |
| 104 | + |
| 105 | + print("\nformat\ncommands\ninput markers\n") |
| 106 | + |
| 107 | + while True: |
| 108 | + user_input = input("[H] ") |
| 109 | + |
| 110 | + |
| 111 | + if user_input == "exit": |
| 112 | + break |
| 113 | + |
| 114 | + if user_input == "format": |
| 115 | + print("I recommend that you don't add any punctuations such as ! or ?. I also don't really care whether you capitalize your sentences or not!") |
| 116 | + continue |
| 117 | + |
| 118 | + if user_input == "commands": |
| 119 | + print("I have some built in commands that you can use such as time and math!") |
| 120 | + print("You start all commands with a \"/\" and then the command. Below is a list of all my commands") |
| 121 | + print("/math - [ALPHA] This is still in development, but right now this is capable of doing basic math with only two numbers.") |
| 122 | + print("/help - This sends you to this page!") |
| 123 | + print("/services - Lists down all the services being used in this program, and gives you the option to disable/enable them") |
| 124 | + print("/time - Prints the time and date! Pretty nifty, huh?") |
| 125 | + print("/sqrt - Brings up the kSquareRoot function for finding the square root of the number you're looking for.") |
| 126 | + continue |
| 127 | + |
| 128 | + if user_input == "input markers": |
| 129 | + print("You might have noticed that when you're typing something in, theres a little box on the left. Here is a list of what they mean:") |
| 130 | + print(" [~] - basic input where you write in a question") |
| 131 | + print(" [H] - help page input for detail on subjects") |
| 132 | + print(" [A] - answering input that will set whatever you write as the answer to your question") |
| 133 | + print(" [S] - service editing input") |
| 134 | + continue |
0 commit comments