#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Dan Gau
#  book.py
from random import randint

class book:
	
	# Creates a book object with the given information, setting
	# the current page to 0.
	def __init__(self, author, thistitle, pages):
		self.author = author
		self.title = thistitle
		self.pages = pages
		self.curpage = 0
		
	# Advances the bookmark by numpages. If there are fewer pages
	# to read, then the curpage is set to the last page.
	def read(self, numPages):
		if self.curpage + numPages > self.pages:
			print("You only had ", self.pages - self.curpage, " pages left so this is what you read.")
			self.curpage = self.pages
		else:
			self.curpage += numPages
		
	# Creates a new Book object with the same author as this Book
	# the same title with “II” appended to it, with numpages
	# number of pages and sets the bookmark to 0. This new object
	# is returned.
	def makeSequel(self, numPages):
		return book(self.author, self.title + " II", numPages)

	# Returns the number of pages left to read in this Book.
	def pagesLeft(self):
		return self.pages - self.curpage
		
	# Returns the number of pages in the Book.
	def getNumPages(self):
		return self.pages

def main():

        # Read in the first book and add in its pages to the total read.
        myBook = book(input("Who wrote your book?\n"), input("What is the title of your book?\n"), int(input("How many pages is your book?\n")))
        totalPages = myBook.pagesLeft();

        # Read first book.
        daysTaken = 0
        print("Now you are reading",myBook.title ,"by",myBook.author,"!")
        while myBook.pagesLeft() > 0:
                daysTaken += 1
                myBook.read(int(input("How many pages did you read on day " + str(daysTaken) + "?\n")))
                print("You have", myBook.pagesLeft(), "pages left")
        print("Congratulations on finishing your book!")
        print("You read",myBook.getNumPages() ,"pages in",daysTaken,"days for an average of",myBook.getNumPages()/daysTaken,"pages/day.")

        # Get the pages for the sequel and add to total.
        pages = int(input("How many pages does the sequel have?\n"))
        myBookSequel = myBook.makeSequel(pages)
        totalPages += pages
        totalDays = daysTaken
        
        # Read second book
        daysTaken = 0
        print("Now you are reading",myBookSequel.title ,"by",myBookSequel.author,"!")
        while myBookSequel.pagesLeft() > 0:
                daysTaken += 1
                myBookSequel.read(int(input("How many pages did you read on day " + str(daysTaken) + "?\n")))
                print("You have", myBookSequel.pagesLeft(), "pages left")
        totalDays += daysTaken

        # Print all remaining output.
        print("Congratulations on finishing your book!")
        print("You read",myBookSequel.getNumPages() ,"pages in",daysTaken,"days for an average of",myBookSequel.getNumPages()/daysTaken,"pages/day.")
        print()
        print("In all, you read ",totalPages," pages in ",totalDays," days for an average of ",totalPages/totalDays," pages/day.")
        
        
main()
