Aug-24-2018, 05:10 PM
Hi all! First trouble: python works with version 3.7 while ptpython works with verion 3.6. How make them both work with 3.7 ?
Second trouble: I have a file made by a professionnal, still I have an error.
Now the error:
Second trouble: I have a file made by a professionnal, still I have an error.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
#!/usr/bin/env python # Script Name : prime_finder.py # Author : Tony Hammack # Created : 23 December 2015 # Last Modified : 4 February 2016 # Version : 1.5 # Classes imported import logging import os import sys from timer import Timer # Classes created class InvalidArgumentException(Exception): # Custom Exception pass # **** Constants **** LOG_FILE = 'prime_finder.log' # Log file MINUTES = 0.5 # user can define global duration in minutes that algorithm can use # ***** Functions *** # Utilities def clear_screen(): "# Function to clear the screen" if os.name = = "posix" : # Unix/Linux/MacOS/BSD/etc return os.system( 'clear' ) # Clear the Screen elif os.name in ( "nt" , "dos" , "ce" ): # DOS/Windows return os.system( 'CLS' ) def new_program(): # New Program clear_screen() load_program() def reload_finder(): # reloads the program response = input ( "Do you want to restart the prime finder? (yes or no): " ) if response = = "yes" : new_program() elif response = = "no" : clear_screen() sys.exit() # closes form def load_program( t = Timer): # Main Program # First Logger log_specifics_debug( 'START' , 'Starting the Prime Finder.' ) # initial variable input try : # User input userString = input ( "Please input an integer: " ) userNumber = int (userString) log_specifics_debug( 'USER INPUT' , 'Input was successful.' ) # Initiates Timer class object t = Timer() start_time = t.start() # Prime Finder prime_finder(userNumber, start_time) log_specifics_debug( 'PRIME FINDER' , 'prime_finder module completed.' ) # Reload prime finder response = input ( "Do you want to restart the prime finder? (yes or no): " ) if response = = "yes" : log_specifics_debug( 'RELOADING' , 'Prime Finder is reloading.' ) new_program() elif response = = "no" : clear_screen() log_specifics_debug( 'CLOSING' , 'Prime Finder is closing.' ) sys.exit() except ValueError as err: log_specifics_debug( 'USER INPUT' , userString) log_specifics_critical( 'USER INPUT' , 'User entered a non-integer literal.' ) # Restarts Prime Finder application response = input ( "Do you want to restart the prime finder? (yes or no): " ) if response = = "yes" : log_specifics_debug( 'RELOADING' , 'Prime Finder is reloading.' ) new_program() elif response = = "no" : clear_screen() log_specifics_debug( 'CLOSING' , 'Prime Finder is closing.' ) sys.exit() except KeyboardInterrupt as err: log_specifics_debug( 'Closing' , 'User has manually closed program.' ) sys.exit() except RuntimeError as err: log_specifics_debug( 'RUNTIME ERROR' , err) # Restarts Prime Finder application response = input ( "Do you want to restart the prime finder? (yes or no): " ) if response = = "yes" : log_specifics_debug( 'RELOADING' , 'Prime Finder is reloading.' ) new_program() elif response = = "no" : log_specifics_debug( 'CLOSING' , 'Prime Finder is closing.' ) clear_screen() sys.exit() # Prime Finder Algorithm def prime_finder(num, p_start): # prime factor algorithm log_specifics_debug( 'START TIME' , 'Start of algorithm: ' + str (p_start)) print ( "Here are your prime factors...." ) mod = 2 while mod < = num: test = compare_time(p_start) if test: while num % mod = = 0 : num = num / mod final_output(mod) # displays output mod + = 1 # increases modulus by one else : print ( "Time of algorithm exceeded predetermined limit of: " + str (MINUTES) + " minutes." ) break log_endoftime(p_start) def final_output(factors): # prints modulus out log_specifics_debug( 'FACTORS' , factors) print (factors) # Timer class objects def start_time(): # Start Time t = Timer() return t.start() def stop_time(): # Stop Time t = Timer() return t.stop() def difference_time(p_start): # Difference between start and end times stop = stop_time() return stop - p_start def compare_time(p_start): # Compares Time seconds = MINUTES * 60 # User can specify seconds to limit program while difference_time(p_start) < seconds: return True return False # Loggers def log_endoftime(p_start): log_stop = stop_time() log_specifics_debug( 'END TIME' , 'End of algorithm: ' + str (log_stop)) log_specifics_debug( 'LENGTH TIME' , 'Time of algorithm: ' + str (log_stop - p_start) + " seconds." ) def log_specifics_debug(section, message): # Logs debug information with section/message log = logging.getLogger(section) log.debug(message) def log_specifics_critical(section, message): # Logs critical information with section/message log = logging.getLogger(section) log.critical(message) def log_specifics_info(section, message): # Logs critical information with section/message log = logging.getLogger(section) log.info(message) def purge_log(): with open (LOG_FILE, 'w' ) as file : file .truncate() # *****Ends Functions**** if __name__ = = "__main__" : # set up logging to file logging.basicConfig(level = logging.DEBUG, format = '%(asctime)s %(name)-12s %(levelname)-8s %(message)s' , datefmt = '%d-%m-%y %H:%M' , # Date Format filename = LOG_FILE, # Name of log filemode = 'a' ) # Appends log # define a Handler which writes INFO messages or higher to the sys.stderr console = logging.StreamHandler() console.setLevel(logging.INFO) # set a format which is simpler for console use formatter = logging.Formatter( '%(name)-12s: %(levelname)-8s %(message)s' ) # tell the handler to use this format console.setFormatter(formatter) # add the handler to the root logger logging.getLogger('').addHandler(console) # Starting program# try : if len (sys.argv) > 1 : # Checks to see if sys.argv has input argv = str (sys.argv[ 1 ]) # purges logs if argv = = '-p' : purge_log() new_program() elif argv = = '--purge' : purge_log() new_program() else : # Raising Custom exemption raise InvalidArgumentException( "User entered " + argv + " as invalid argument." ) else : new_program() except InvalidArgumentException as err: log_specifics_debug( 'INVALID ARGV' , err) sys.exit() # **** End Program |
Error:Please input an integer: 145
Traceback (most recent call last):
File "big.py", line 225, in <module>
new_program()
File "big.py", line 42, in new_program
load_program()
File "big.py", line 69, in load_program
t = Timer()
TypeError: Timer takes at least 2 arguments