You are on page 1of 13

Python 3.

7 – Session 1: How to start (0900-0915)

1. What is the software name you are going to learn?

2. What is the URL address to download Python software?

3. What are the Python version available to be downloaded/installed?

4. What are the Python version should be downloaded/installed in your personal computer?

5. What should you do next in order to download the Python installer?

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?

10. What is the icon for the Python program?

11. How to start the Python program?

12. How to use the Python program?

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)

1. Refer to Figure 1 below, do you know the name of the objects?

Figure 1: Name of the objects

2. What are the objects that we can put in the envelop?

3. Refer to Figure 2 below, can you give a better name for the object?

Figure 1: Name for the objects

In Python, we can insert Text, Numbers, and Booleans to a program.

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.

5. How to recall / print out your name in the Python IDE?

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.

7. How many objects can be stored in your pet name?

You only can store only one object in the variable that you have declared.

Challenge 1: Try it yourself (Integer and Floats)

a. Insert the following codes in your python IDE.


number_1 = int(10)
number_2 = int(40)
number_3 = float(-13.9)
number_4 = float(14.91)
my_name = str(“Ali”)
my_daddy_name = str(“Abu”)

b. Then, print out all variables on the screen.

Challenge 2: Try it yourself (Basic Arithmetic Operators)

a. Find the sum of number_1 and number_3.


b. Find the deduction of number_2 and number_4.
c. Find the multiplication of number_1 and number_4.
d. Find the division of number_2 and number_4.
e. Can we sum number_1 and my_name?
f. Can we multiply number_3 and my_daddy_name?

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.

2. Insert the following codes in the Python file.


a = 4
b = 6
c = -1
print(a+c)

3. How to replace the variable of a from user input?

4. Replace variable b and c using user input as well.

Challenge 4: Try it with your friend (Input and 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

• Your output screen may look like this

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)

Challenge 5: Try it with your friend (Comparison Operators)

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.

Table 1: Examples for Comparison Operators

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.

Table 2: Program Age

If age Messages for output screen


<3 You are an infant
< 12 You are a kid
< 19 You are a teenager
>= 19 You are an adult

Challenge 6: Try it with your friend (Logical If-else)

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.

Table 3: Program Marks and Grades

If marks Messages for output screen


0-39 You have failed the test
40-59 You got D
60-79 You got C
80-89 You got B
90-100 You got A
Others Wrong input
Challenge 7: Try it with your friend (Looping)

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?

Python 3.7 – Session 6: Looping – while loop (1400-1500)

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?

Challenge 8: Try it with your friend (Looping)

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.

Python 3.7 – Session 7: Looping – for loop (1500-1600)

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.

for x in range(2, 6):


print(x)

4. Then, replace the following codes in the program. Run the program. Then, explain the changes.

for x in range(2, 30, 3):


print(x)

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.

Challenge 10: Try it with your friend (Looping)

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

Python 3.7 – Session 8: Functions (1600-1700)

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.

1. First function should group the even number statements.


2. Second function should group the odd number statements.

Challenge 13: Try it with your friend (Function)

Reuse the coding in Challenge 7, insert function(s) in the codes.

1. Do you think it is necessary to create a function in this program?


2. Explain your answer in 1.

You might also like