print "Hello World!"

"""
Explanation: CH 1 Syntax
In this tutorial notebook, you will learn how to do programming in python and jupyter. Open a new notebook in ipython or https://try.jupyter.org/, try to "copy" and "paste" the following codes.
Jupyter
- Basic operations:

Click on the cell to select it.
Press SHIFT+ENTER on your keyboard or press the play button (<button class='fa fa-play icon-play btn btn-xs btn-default'></button>) in the toolbar above.
Open new cells using the plus button (<button class='fa fa-plus icon-plus btn btn-xs btn-default'></button>)

Simple statements : Hello World

The first thing we do is to print a phrase "Hello World!" using python
The "print" command with an "object" print your object to the terminal
Noted that "print" command can only used in python 2. In python 3 you have to use "print(your-object)" function
End of explanation
"""


print "Tips 1: And Enter makes a new line in a cell"
print "Tips 2: Print also output line by line"

print "Tips 3: Use \ to escape an characters like \""
print "Tips 4: Use \\n \n to make a newline character"
print '''Tips 5: Use three \' to 
make 
multiple 
line
''' 

"""
Explanation: Hello World! in other language
Fortran
PROGRAM HELLO
    WRITE (*,100)
    STOP
100 FORMAT (' Hello World! ' /)
    END
Lisp
(print "Hello World")
C++
```
include <iostream.h>
main()
{
    cout << "Hello World!" << endl;
    return 0;
}
```
Java
class HelloWorld {
  static public void main( String args[] ) {
    System.out.println( "Hello World!" );
  }
}
Matlab
disp('Hello World');
JavaScript
document.write('Hello World!')
End of explanation
"""


time.sleep(0.5);
print "Too bad"

import time
time.sleep(0.5);
print "Now its work"

print "We delete the time object to unload it from memory"
del time
time.sleep(0.5);

"""
Explanation: Import package and library
Python is rich in library. Use expression like
Import xxxxxxx
or
from xxxxxxx import yyyyyy
to import library provided that you know the name of your library xxxxxx and objects yyyyyyy in the library xxxxxxx.
Package is not loaded at the beginning, you need to import it before using it.
Example: Time module
End of explanation
"""


a = 10
print a

"""
Explanation: Integer
Declaring variable is simple, just put an equal sign to a variable name. Print it with the variable name:
End of explanation
"""


a = 10
b = 15
print a + b , a - b , a * b , a / b

"""
Explanation: You can print different variables at the same time with comma-separated, and the different arthimatic operations are showned
End of explanation
"""


f1 = 10.
f2 = 10.2
f3 = 1e9
f4 = 1e-9
f5 = .1
print f1,f2,f3,f4,f5

"""
Explanation: Float
f1 miss the zero, f2 is a usual float number, f3 and f4 use scientific notation, all are float numbers
End of explanation
"""


f1 = 1e9
f2 = 1e-9
print f1 + f2 , f1 - f2 , f1 * f2 , f2 / f1

"""
Explanation: And the different arthimatic operations of floats are showned
End of explanation
"""


s1 = "HK"
s2 = 'U'
s3 = s1 + s2
print s1,s2,s3

"""
Explanation: String
s1 use double quote, s2 use single quote, s3 concatenate s1 and s2
End of explanation
"""


s1 = "The University of Hong Kong"
print s1
print s1.replace("Hong Kong","Pok Fu Lam")

"""
Explanation: The dot replace function replace a word "Hong Kong" in s1 to "Pok Fu Lam"
End of explanation
"""


s1 = "The University of Hong Kong"
print s1[0]
print s1[4]
print s1[18]
print s1[23]

"""
Explanation: Each character can be obtained by giving an index of the string, noted that it starts from zero
End of explanation
"""


s1 = "The University of Hong Kong"
print s1.split()
s2 = "11 12 13 14 15"
print s2.split()
s3 = "11.12,13.14,15"
print s3.split(',')

"""
Explanation: Split is a powerful function that split a string with a character into a list (array)
End of explanation
"""


print "A %s C" % "F"

"""
Explanation: More about string in a statement
Use %s to act as a placeholder in output
print "........%s......." % your-variables
End of explanation
"""


print "A %s C %s" % ("B","D") 

"""
Explanation: Use a bracket at the end if you use two or more placeholders
End of explanation
"""


print "A %s C %s" % (1,2) 

"""
Explanation: If your input is not a string, in this case it is an integer, it will convert to string automatically
End of explanation
"""


print "A %s C %s" % (1e-8,2e6) 

"""
Explanation: Same for float numbers, but the formats depends
End of explanation
"""


print "1 Digit: %.1f" % 3.1415929
print "2 Digit: %.2f" % 3.1415929
print "3 Digit: %.3f" % 3.1415929
print "4 Digit: %.4f" % 3.1415929

"""
Explanation: If you need precision in the printed float, use
End of explanation
"""


print "1 Digit: %.1e" % 3.1415929
print "2 Digit: %.2e" % 299792458
print "3 Digit: %.3e" % 299792458
print "4 Digit: %.4e" % 6.62607004e-34

"""
Explanation: If you need precision in the scientific notation, use
End of explanation
"""


b1 = True
b2 = False
b3 = (b1 and b2) or (b1 or b2)
print b1,b2,b3

"""
Explanation: Boolean
Boolean can be defined by True or False, and support basic logical operation.
End of explanation
"""


print('Hello World!')

from __future__ import print_function
print('Hello World!')

"""
Explanation: Example: Input from future
If you need the print() function in python 3, input it from future
End of explanation
"""


