#!/usr/bin/env python3 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. import sys def main(): if len(sys.argv) == 1: read = get_int("Read? ") total = get_int("Total? ") elif len(sys.argv) >= 3: read, total = user_input() # Help message, user can enter -h or --help because it will not make the previous statements true else: print("Usage: {0} [read total]".format(sys.argv[0]), "\nArguments not required, but must be used together.") sys.exit() not_read = total - read half = total // 2 print_info(read, not_read, half, total) def get_int(msg): while True: i = input(msg) try: return int(i) except ValueError as err: print(err) continue def user_input(): try: read = int(sys.argv[1]) total = int(sys.argv[2]) return read, total except ValueError as err: print(err) sys.exit() def print_info(read, not_read, half, total): if read > total: print(" Ha, funny, you read {0} pages, but there are only {1} total?".format(read, total)) elif read == total: print(" Really? You're done with {0} pages?".format(total)) elif read == 0: print(" Um? You haven't even start a book with {0} pages?".format(total)) elif read < half: print(" There are {0} pages total. \n You have only read {1} pages. \n There are {2} pages that you haven't read!".format( total, read, not_read)) elif read > half: print(" There are {0} pages total. \n You read {1} pages. \n Almost there, only {2} pages that you haven't read!".format( total, read, not_read)) elif read == half: print(" There are {0} pages total. \n You read {1} pages. \n There are {2} pages that you haven't read. \n Congrats, you at the halfway point!".format( total, read, not_read)) if __name__ == "__main__": main()