Python For Teachers - 27 Aug 2018
Python For Teachers - 27 Aug 2018
4. What are the Python version should be downloaded/installed in your personal computer?
6. What should you do next after you have downloaded the Python installer?
7. You may see the following screen after you have double click the Python installer. What should
you do next?
8. You should see these screens after you have clicked the “Install Now”. What should you do next?
9. Setup was successful, if you have seen this screen. What should you do next?
13. Try type word “hello” and then press Enter button. What is happening?
14. Click “File” in the Menu Bar. Then, select “New File”.
15. Type print(“Welcome to Python class”)
16. Press Key “F5”and click the “OK” button. What is happening? What should you do? Give a name
for your file.
Python 3.7 – Session 2: Variable Declaration and Data Type (0915 - 1000)
3. Refer to Figure 2 below, can you give a better name for the object?
Data Type
Text
Number Boolean
Char
Integer: True:
A, c, d, E, &, $
-112, 0, 43, 121312 Displayed as True
String
Float False:
Sabah, hello, apa
1.8, -12.0. 14.012 Displayed as False
khabar
4. Instruction: Declare a variable name that can store your own name. Assign your own name in the
variable.
6. Instruction: Declare a variable name that can store your pet name. Assign your pet’s name in the
variable and then display in the screen.
You only can store only one object in the variable that you have declared.
In any programming, sum uses symbol +, minus uses symbol -, multiplication uses symbol *, and
divide uses symbol /.
Challenge 3: Try it yourself (String Manipulation) (1030-1100)
1. Open a new Python file, save the file in the Desktop folder, and give the name as
string_manipulation.
2. Insert the following codes in the Python file. Then, try to explain the differences between the
symbols used in the codes.
statement_1 = “Hello”
statement_2 = ‘Welcome’
3. Continue to insert the following code in the Python file. What is happening after you run the file?
print(statement_1 + statement_2)
4. Continue to insert the following codes in the Python file. What is happening after you run the file?
print(len(statement_1))
print(len(statement_2))
5. Continue to insert the following codes in the Python file. What is happening after you run the file?
print(statement_1[2])
print(statement_2[3])
print(statement_2[7])
6. Continue to insert the following codes in the Python file. What is happening after you run the file?
print(statement_1, statement_2)
print(statement_2*3)
print(statement_1*2)
7. Continue to insert the following codes in the Python file. What is happening after you run the file?
print(“:”.join(statement_1))
print(“ ”.join(statement_2))
Python 3.7 – Session 3: Input and Output (1100 - 1130)
1. Open a new Python file, save the file in the Desktop folder, and give the name as input_output.
1. Write a program that accept user inputs for variables nom1, nom2, nom3.
2. Print out the answers for:
a. nom1 + nom2 + nom3
b. nom1 + nom2 – nom3
c. nom2 * nom3
d. nom3 / nom1
The input function can capture anything from user inputs including string and character.
Python 3.7 – Session 4: Comparison Operators (1130-1200)
Operators Descriptions
== If two variables are same, then it will return True
!= If two variables are different, then it will return True
> If left variable is larger than right variable, then it will return True
< If left variable is smaller than right variable, then it will return True
>= If left variable is larger than or equal to the right variable, then it will
return True
<= If left variable is smaller than or equal to the right variable, then it
will return True
1. Open a new Python file, save the file in the Desktop folder, and give the name as
comparison_operators.
2. Insert the following codes in the Python file. What is the output?
a = 4
b = 6
print(a==b)
1. Discuss the answers for expressions given in Table 1 (Don’t type in the python IDLE)
2. Find the answer for all of the expressions given in Table 1 by using Python programming.
x = 56 x = 56.3 x = 56 x = “apple”
y = 78 y = 56.02 y = 56 y = ‘apple’
print(x > y) print(x >= y) print(x == y) print(x != y)
x = 56 x = 19 x = 56 x = “apple”
y = 78 y = 91 y = 56 y = “Apple”
print(x is 56) print(x <= y) print(x = y) print(x == y)
x = 56 x = 1 x = 2 x = 91
y = 78 y = ‘apple’ y = 4 y = 91.2
print(y < x) print(x == y) print(x == (y*2)) print(x = y)
x = 56 x = 1.2 x = 23 x = 0
y = 78 y = 3.2 y = 12 y = 3
print(x is y) print(x != y) print(x != y) print(x < 5)
Python 3.7 – Session 5: Logical Operators (1200-1330)
Logical
if if-elif-else
if-else
Only involve one Involve more than two
Involve two selections
selection selections
1. Open a new Python file, save the file in the Desktop folder, and give the name as
logical_gender.
2. Write a program that prompt for gender. Then, the program should display “Male” if user input
is 1 and display “Female” if user input is 2.
3. Open a new Python file, save the file in the Desktop folder, and give the name as logical_age.
4. Write a program that prompt for age. Follow Table 2 for displaying the messages.
Open a new Python file, save the file in the Desktop folder, and give the name as logical_grade.
Write a program that prompt for marks. Follow Table 3 for displaying the messages.
Design and implement an interactive program that reads a temperature value in degrees either
Centigrade or Fahrenheit. Then, convert it and display the outputs.
How do you know that the input is in Centigrade or Fahrenheit? How do you solve this
problem?
What are the formula used to convert Centigrade to Fahrenheit and vice versa?
1. Open a new Python file, save the file in the Desktop folder, and give the name as
looping_number.
2. Insert the following codes in the program. Run the program. Then, explain the codes.
i = 1
while i < 6:
print(i)
i += 1
3. Then, replace the following codes in the program. Run the program. Then, explain the changes.
i = 1
while i < 6:
i += 1
print(i)
4. Slightly improve the program by prompting the user to input the target stop value. User can insert
any value to the system.
5. Slightly improve the program by prompting the user to input the startup value. User can insert
any value to the system.
6. Test the program with startup value as 5 and target value as 4. Run the program. Does the
program work well? Why? How to improve it?
Open a new Python file, save the file in the Desktop folder, and give the name as
loop_for_even_number. Write a program that prompt for startup and target numbers. Then, display
all even numbers between the startup and target numbers.
Challenge 9: Try it with your friend (Looping)
Write a program that reads a positive single-digit integer and prints the word equivalent for it. For example,
if the user enters 8, your program should print “You have entered eight”. The program should execute
repeatedly until the user enters a negative digit.
1. Open a new Python file, save the file in the Desktop folder, and give the name as
looping_number_for.
2. Insert the following codes in the program. Run the program. Then, explain the codes.
for x in range(6):
print(x)
3. Insert the following codes in the program. Run the program. Then, explain the codes.
4. Then, replace the following codes in the program. Run the program. Then, explain the changes.
5. Slightly improve the program by prompting the user to input the target stop value. User can insert
any value to the system.
6. Slightly improve the program by prompting the user to input the startup value. User can insert
any value to the system.
Write a program to read a single integer from user. Then, print the symbol based on user inputs. Example,
if user entered 3, then the symbol should look like Figure 2 and if user entered 5, then the symbol should
look like Figure 3.
if user entered 3, if user entered 5,
* *
** **
*** ***
****
*****
Figure 2: User entered 3 Figure 3: User entered 5
Challenge 11: Try it with your friend (Looping)
Write a program to receive user inputs for integers “start” and “stop”. Then, improve the program to print
out the odd numbers from the “start” and “stop” variables. After that, improve the program to print out
the even numbers. Make sure you use two separate for loops in your program. You program may look
like Figure 4 below.
Please enter start number: 1
Please enter stop number: 9
Odd numbers:
1
3
5
7
Even numbers:
2
4
6
8
Figure 4: For looping program to print odd and even numbers
1. Open a new Python file, save the file in the Desktop folder, and give the name as func_test01.
2. Insert the following codes in the program. Run the program. What is happening? Try to explain
the codes.
def my_program():
for x in range(6):
print(x)
3. Then, improve the program by inserting the following code in line 5. Run the program again. What
is happening?
my_program():
4. Insert the following codes in line 7 in the program. Run the program. What is happening? Try to
explain the codes.
def my_function(x):
return 5 * x
print(my_function(3))
print(my_function(5))
print(my_function(9))
Challenge 12: Try it with your friend (Function)
Reuse the coding in Challenge 11, insert two functions in the codes.