Errata

Python: Learn Python in One Day and Learn It Well (2nd Edition)


Chapter 3: The World of Variables and Operators Page 15, Special Thanks to David Hill

A variable name in Python can only contain letters (a - z, A - B), numbers or underscores (_).

should be

A variable name in Python can only contain letters (a - z, A - Z), numbers or underscores (_).

Chapter 10: Object Oriented Programming Part 2 Page 113, Special Thanks to David Wincelberg

hasttr()

should be

hasattr()

Python: Learn Python in One Day and Learn It Well


Project: Math and BODMAS Page 76, Special Thanks to Andrew S. Neumann

Here we'll define our first function. Let's call it getUserPoint().

should be

Here we'll define our first function. Let's call it getUserScore().

Appendix A Page 94, Special Thanks to Herbie Wu

index() returns ValueError is sub is not found

should be

index() returns ValueError if sub is not found

Appendix A Page 99, Special Thanks to Herbie Wu

sep.join(myTuple)
 =>'d-e-f'

should be

sep.join(myList)
 =>'d-e-f'

Appendix E Page 116-117, Special Thanks to Andrew S. Neumann

Indentation of else-block for Exercise 3 is wrong

else:
   input = open('userScores.txt', 'r')
   output = open('userScores.tmp', 'w')
for line in input:
   content = line.split(',')
   if content[0] == userName:
      content[1] = score
      line = content[0] + ', ' + content[1] + '\n'

   output.write(line)
input.close()
output.close()

remove('userScores.txt')
rename('userScores.tmp', 'userScores.txt')

should be

else:
   input = open('userScores.txt', 'r')
   output = open('userScores.tmp', 'w')
   for line in input:
      content = line.split(',')
      if content[0] == userName:
         content[1] = score
         line = content[0] + ', ' + content[1] + '\n'

      output.write(line)
   input.close()
   output.close()

   remove('userScores.txt')
   rename('userScores.tmp', 'userScores.txt')

Appendix E Page 117, Special Thanks to Kyle Chen

if index > 0 and operatorList[index-1] != '**':
    operator = operatorDict[randint(1, 4)]
else:
    operator = operatorDict[randint(1, 3)]

should be

if index >= 0 and operatorList[index-1] != '**':
    operator = operatorDict[randint(1, 4)]
else:
    operator = operatorDict[randint(1, 3)]

When index equals 0, all four operators (including the ** operator) are allowed. Hence, we want the if block to be executed.

When we change the if condition to

if index >= 0 and operatorList[index-1] != '**'

the if block will be executed when index equals zero as operatorList[index-1] (i.e. operatorList[-1]) will be equal to ''. Hence, both conditions will be true.


Appendix E Page 120, Special Thanks to Ernie Tam

if index > 0 and operatorList[index-1] != '**':
    operator = operatorDict[randint(1,4)]
else:
    operator = operatorDict[randint(1,5)]

should be

if index >= 0 and operatorList[index-1] != '**':
    operator = operatorDict[randint(1,5)]
else:
    operator = operatorDict[randint(1,4)]

C#: Learn C# in One Day and Learn It Well

Update: 19 Mar 2017

Microsoft updated Visual Studio Community two weeks ago. If you are using the new version (VSC 2017), please select .Net desktop development  when installing (refer to screenshot below).


An updated version of the book was published in Mar 2017 to include new download instructions for VSC 2017. Unless otherwise stated, the page numbers refer to the OLD edition. If you are using the updated version, please add one to the page numbers indicated below. Special Thanks to Daniel Rioux for highlighting this.


Chapter 2: Getting ready for C# Page 11, Special Thanks to James Czekaj

For instance, when you type a period (.) after the word "Console", a dropdrop list appears to let you know what you can type after the period.

should be

For instance, when you type a period (.) after the word "Console", a drop-down list appears to let you know what you can type after the period.

Chapter 3 Page 17, Special Thanks to Christian Sasso

float can store numbers from -3.4 x 1038 to +3.4 x 1038. It uses 8 bytes of storage and has a precision of approximately 7 digits.

should be

float can store numbers from -3.4 x 1038 to +3.4 x 1038. It uses 4 bytes of storage and has a precision of approximately 7 digits.

Chapter 3 Page 17, Special Thanks to Jeff Murray

This means that if you use float to store a number like 1.23456789 (10 digits), the number will be rounded off to 1.234568 (7 digits).

should be

This means that if you use float to store a number like 1.23456789 (9 digits), the number will be rounded off to 1.234568 (7 digits).

Chapter 5 Page 38, Special Thanks to Christian Sasso

The difference between WriteLine() and Write() is that Writeline() moves the cursor down to the next line after displaying the message while Write() does not.

should be

The difference between WriteLine() and Write() is that WriteLine() moves the cursor down to the next line after displaying the message while Write() does not.

Chapter 6 Page 51, Special Thanks to Ram Mitra and Jerry Myer

11 <= 7 is true

should be

11 <= 7 is false

Chapter 6 Page 56, Special Thanks to Christian Sasso

The pseudo code for the switch statement

switch (variable used for switching)
{
   case firstCase:
      do A;
      break (or other jump statements);
   case secondCase:
      do B;
      break (or other jump statements);
   case default:
      do C;
      break (or other jump statements);
}

should be

switch (variable used for switching)
{
   case firstCase:
      do A;
      break (or other jump statements);
   case secondCase:
      do B;
      break (or other jump statements);
   default:
      do C;
      break (or other jump statements);
}

Chapter 6 Page 67-68, Special Thanks to Ram Mitra

If you enter

10

You will get

Index was outside the bounds of the array. Index should be from 0 to 5.

If you enter

Hello

You will get

Input string was not in a correct format. You did not enter an integer.

should be

If you enter

10

You will get

Index should be from 0 to 5.

If you enter

Hello

You will get

You did not enter an integer. 

Chapter 7 Page 72, Special Thanks to Stephen S. Baca

One of the main reasons is that using properties gives us greater control over what rights other classes have when assessing these private fields. We’ll see how to do that later.

should be

One of the main reasons is that using properties gives us greater control over what rights other classes have when accessing these private fields. We’ll see how to do that later.

Chapter 7 Page 75, Special Thanks to Dr CL Tondo

value is a keyword when it used inside a setter.

should be

value is a keyword when it is used inside a setter.

Chapter 7 Page 78, Special Thanks to Ram Mitra

In C# (and most other languages), you can create two methods of the same name as long as they have different signatures.

should be

In C# (and most other languages), you can create two or more methods of the same name as long as they have different signatures.

Chapter 7 Page 82, Special Thanks to Ram Mitra

After creating our staff1 object, the next line shows how we can use the public EmployeeType property to assign a value to the hWorked field.

should be

After creating our staff1 object, the next line shows how we can use the public HoursWorked property to assign a value to the hWorked field.

Chapter 8 Page 101, Special Thanks to Ram Mitra

Now that we have seen an example of how inheritance woks

should be

Now that we have seen an example of how inheritance works

Chapter 8 Page 107, Special Thanks to Ram Mitra

Interfaces are much like abstract classes in that they cannot be instantiated and must be inherited.

should be

Interfaces are much like abstract classes in that they cannot be instantiated and must be inherited from.

Chapter 11 Page 122, Special Thanks to Vaskor Basak

Notice that we create this StreamReader instance inside a pair of parenthesis that follows the word using on line 2?

should be

Notice that we create this StreamReader instance inside a pair of parentheses that follows the word using on line 2?

Chapter 11 Page 126, Special Thanks to Jerry Myer and Ram Mitra

using(StreamWriter sw=new StreamWriter(path, true)) 
{ 
   sw.WriteLine("ABC"); 
   sw.WriteLine("DEF");
   sw.Close();
}

should be

using(StreamWriter sw=new StreamWriter(path, true)) 
{ 
   sw.WriteLine("ABC"); 
   sw.WriteLine("EFG");
   sw.Close();
}

Project: A Simple Payroll Software Page 128, Special Thanks to Vaskor Basak

The Staff class contains information about each staff in the company.

should be

The Staff class contains information about each staff member in the company.

Project: A Simple Payroll Software Page 129, Special Thanks to Ram Mitra

In addition to these three auto-implemented methods, the Staff class also has a public property called Hours Worked.

should be

In addition to these three auto-implemented properties, the Staff class also has a public property called Hours Worked.

Project Page 137, Special Thanks to Jerry Myer

Based on the value of result[1], we use an if statement to create a Manager object if the value of result[1] is "Manager" or an Admin object if the value is "Admin".

should be

Based on the value of result[1], we use an if statement to create a Manager object if the value of result[1] is "Manager", or an Admin object if the value is "Admin".

A comma should be added before the words “or an Admin object”.


Appendix A – Project Answer Page 151, Special Thanks to Ram Mitra

For the Manager class:

The method below updates the total pay when HoursWorked is greater than 160. However, an allowance of 1000 is written in the payslip (even though it is not added to the manager’s total pay) when the manager has worked less than 160 hours.

public override void CalculatePay() 
{ 
   base.CalculatePay();

   Allowance = 1000;

   if (HoursWorked > 160) 
      TotalPay = BasicPay + Allowance; 
}

A better solution (provided by Ram Mitra) is:

public override void CalculatePay()
{
   base.CalculatePay();
   Allowance = 0;
   
   if (HoursWorked > 160)
   {
      Allowance = 1000;   
      TotalPay = BasicPay + Allowance;
   }
}

Appendix A – Project Answer Page 152, Special Thanks to Ram Mitra

For the Admin class:

public override void CalculatePay() 
{ 

   base.CalculatePay();
   if (HoursWorked > 160) 
      Overtime = overtimeRate * (HoursWorked - 160);

}

should be

public override void CalculatePay() 
{ 

   base.CalculatePay();
   if (HoursWorked > 160)
   {
      Overtime = overtimeRate * (HoursWorked - 160); 
      TotalPay = BasicPay + Overtime;
   }

}

The line TotalPay = BasicPay + Overtime; is missing from the if-statement. This results in the total pay not being updated when HoursWorked is greater than 160.


CSS: Learn CSS in One Day and Learn It Well


Chapter 8 Page 107 Exercise 8.1 Paragraph 2, Special Thanks to Bruce Beach

The current font family is Sans Serif.

should be

The current font family is Serif.

Java: Learn Java in One Day and Learn It Well


Chapter 7 Page 84, Special Thanks to Aaron Redshaw

There can be more than one packages within a single Java application. Refer to Chapter 2.3.1 if you have forgotten what a package is.

should be

There can be more than one package within a single Java application. Refer to Chapter 2.4.1  if you have forgotten what a package is.

Chapter 10: File Handling Page 162, Special Thanks to George Lykovitis

line = reader.readerLine();

should be

line = reader.readLine();

SQL: Learn SQL (using MySQL) in One Day and Learn It Well


Chapter 13: Project Page 121, Special Thanks to Robert Strunce

The pending_terminations table has four columns: id, email, request_date and payment_due.

The data types and constraints of the id, password and payment_due columns match that of the same columns in the members table.

should be

The pending_terminations table has four columns: id, email, request_date and payment_due.

The data types and constraints of the id, email and payment_due columns match that of the same columns in the members table.

Appendix C: Suggested Solution for Project, Special Thanks to GuanJie Sun

CREATE PROCEDURE view_bookings (IN p_id VARCHAR(255))
BEGIN
	SELECT * FROM member_bookings WHERE id = p_id;
END $$

should be

CREATE PROCEDURE view_bookings (IN p_id VARCHAR(255))
BEGIN
	SELECT * FROM member_bookings WHERE member_id = p_id;
END $$

If you find any bugs/typo, please let me know. Thanks a million!