You are on page 1of 37

HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY

SCHOOL OF INFORMATION AND COMMUNICATION TECHNOLOGY

PRACTICE GUIDELINE DOCUMENT


IT1110E – INTRODUCTION TO PROGRAMMING
(INTERNAL CIRCULATION)

© 2020 – HUST – SOICT


1

TABLE OF CONTENT
1. INTRODUCTION ................................................................................................. 2
1.1. PURPOSE AND SCOPE OF THE DOCUMENT ................................................................ 2
1.2. INTENTION OF PRACTICE ......................................................................................... 2
1.3. OTHER INFORMATION ............................................................................................. 3

2. REGULATIONS.................................................................................................... 3
2.1. GENERAL REGULATIONS .......................................................................................... 3
2.2. ASSESSMENT............................................................................................................ 4
2.3. PRACTICE SCHEDULE ............................................................................................... 5

3. PRACTICE EXERCISES NUMBER 1 ...................................................................... 7


3.1. SCREEN SHARING ..................................................................................................... 7
3.2. INSTALL ADDIN WINDCRIBE ON CHROME BROWSER ............................................... 9
3.3. CODEFORCES HANDLE REGISTRATION ................................................................... 11
3.4. HUST-IT FUNDAMENTAL GROUP MEMBER REGISTRATION ..................................... 13
3.5. SUBMISSION IN CODEFORCES SYSTEM ................................................................... 16
3.6. ANACONDA INSTALLATION .................................................................................... 21
3.7. EXERCISES ............................................................................................................. 24

4. PRACTICE EXERCISES NUMBER 2 .................................................................... 27


5. PRACTICE EXERCISES NUMBER 3 .................................................................... 30
6. PRACTICE EXERCISES NUMBER 4 .................................................................... 33
7. PRACTICE EXERCISES NUMBER 5 .................................................................... 35

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
2

1. INTRODUCTION
1.1. PURPOSE AND SCOPE OF THE DOCUMENT
This document has prepared by the SoICT for DS-AI students learning to
practice IT1110E module – Introduction to Programming with Python. This
document and other supporting materials (will be provided during practice time
based on the actual requirements or changing in content) are provided freely to
students in electronic format ( soft-copy) via online teaching channel (Microsoft
Teams) or via email system of HUST.

1.2. INTENTION OF PRACTICE


This practising module requires students to build up programs in Python to
meet the basics of programming including: i) basic concepts of programming such
as variable, expression, statements, control flow, function; ii) basic data types and
structures such as strings, lists, files, classes; iii) basic concepts of exceptions,
testing and debugging. This course helps students to feel justifiably confident of
their ability to write small programs that allow them to accomplish useful goals.
Students will become familiar with the Codeforces system - an nline
programming marking system. Students are required to join the Codeforces system
and then master the submission of programming exercises in the Python to the
Codeforces system.
Students will be guided to deploy Anaconda which is a free and open-source
distribution of the Python for scientific computing (data science, machine learning
applications, large-scale data processing, predictive analytics, etc.). The Anaconda
distribution includes data-science packages suitable for Windows, Linux, and
macOS.

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
3

1.3. OTHER INFORMATION


Students are recommended to join the Group of Computer Center – SoICT-
HUST on Facebook to update information related to practice, share and ask /
answer questions related to knowledge and techniques. skills and processes in
practice exercises. Access and join the following link:
https://www.facebook.com/groups/594924281117643
Students are also recommended to join the Group of Applied Algorithms
on Facebook to get the knowledge how to design, analyse and implement
Algorithms. Access and join the following link:
https://www.facebook.com/groups/886100791516238

2. REGULATIONS
2.1. GENERAL REGULATIONS
When studying online, students take part in a practice session by logging
into the MS Teams online teaching system. Students must be responsible for
managing their accounts and using them for the purpose of studying. Lending
account to others is strictly prohibited.
When participating in the online practice session, students follow the rules
of the classroom, practice under the guidance of lecturers and teaching assistants
(TA). Log in to the practice class on time. Before each practice session, students
should carefully read the provided materials. Students have to read carefully all
instructions for each exercise and listen to the lecturer giving key points to practice.
Students are encouraged to actively ask questions and increase interaction
in the online classroom environment even after the practical session. Students can
leave questions related to practical knowledge and wait for the teacher or teaching
assistant to answer. Students should also actively participate in Q&A topics on the
Computer Center or Applied Algorithms Facebook Groups to stay up to date with
the latest information related to the practice activities.

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
4

2.2. ASSESSMENT
a) IT1110E :

Module Evaluation method Detail Percent

A1. Mid-term (*) Progress 50%

A1.1. Written 20%


Mid-term exam

A1.2. Written 10%


Homework

A1.3. Practice CodeForces 20%


Evaluation
Systems

A2. Final term A2.1. Final exam Written exam 50%

b) How to evaluate practice progress


Evaluate 05 practice sessions: score on a scale of 10 for programming and submit
code to CodeForces.
Scoring method for each practice exercise: Each practice exercise will have a
number of sub-exercises that require students to complete and submit on the
Codeforces system. Each student is required to complete a minimum number of
sub-exercises. Students are encouraged to do all sub-exercises in each exercise to
get the highest possible score. For each problem, if accepted by CodeForces and
true for all Test cases, it will be scored 100 points as the following table. In addition,
depending on the level of completion and the number of correct test cases, the
score may be below 100 (20, 40, 60 ...).

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
5

Practice No The number of Minimum Maximum point


problems (sub- submissions
exercises)

1 5 5 500

2 5 4 500

3 5 4 500

4 5 4 500

5 5 3 500

Total 25 20 2500

For example: Student Nguyen Van An after 05 practice sessions completes a total
of 21 sub-exercises and a total score of 1700 points (the students do not reach the
maximum score). So after converting, 1700/2500 = 0.68 = 6.8 points for practice
exercises submitted on the Codeforces system.

2.3. PRACTICE SCHEDULE


The whole process of practice for each class takes place in 05 sessions (class
meeting), each session has 03 periods (45 minutes each). Students update their
practice schedule on SIS and participate in the practice room or online on MS
Teams according to the instructions and notifications from the lecturers via the e-
mail system of Hanoi University of Technology. Students have a practice schedule
to enter the practice room / MS Teams 10 minutes early before the practice time.
There are two important information including the CLASS ID and TIME as
shown below, students need to remember correctly to enter the right class and
practice team, to avoid deviations about future assessment.

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
6

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
7

3. PRACTICE EXERCISES NUMBER 1


3.1. SCREEN SHARING
If students learn to practice on MS Teams system, one of the features that
students are interested in is how to ask questions or ask lecturers or TA to debug
or guide how to fix them or solve problems encountered in the online learning
process. The following guide will help students use the Chat feature to ask
questions and be instructed by teachers or TA to access students' computers.
Step 1: Students click on the MS Teams Chat function as shown below, then
select the icon to create a new Chat session and type the email of the lecturer TA
to start chatting

1. Click here to open


new chat session
function

1. Click
here to
enter chat
function

Step 2: Students can share screens, Anacoda Navigator / Spyder (Python


3.7) interface window, or documents that want to ask, ask for help by clicking
Screen Sharing button

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
8

Share Spyder
window Share button

Step 3: Students send control of the shared screen or window to the teacher
or TA by pressing the Give Control button and selecting the name of the teacher /
TA to ask for permission

Give control to
lecturer or TA

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
9

Step 4: Talking directly with lecturers / TA via mic, lecturers or TA can


interact directly with students as shown below.

3.2. INSTALL ADDIN WINDCRIBE ON CHROME BROWSER


Sometimes, Codeforces system is blocked by unknown reasons in Vietnam.
Students need to install the Windcribe VPN addin on Chrome browser to access the
Codeforces "smoothly".
Step 1: Open Chrome browser, type the address below:
https://chrome.google.com/webstore/detail/windscribe-free-proxy-and/hnmpcagpplmpfojmgmnngilcnanddlhb

Step 2: Click Add to Chrome

Step 3: Click Add Extention

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
10

Step 4: When using, click on the Windcribe button on the right of the
browser address box as shown below and log in to use. Each account has a free
volume of 10Gb/month (recommended to use only for submitting programs to
avoid insufficient traffic). If the student do not have an account, press the SIGN UP
button

Step 5: (If the student does not have an account): After clicking the SIGN UP
button (or go to the following link: https://windscribe.com/signup?ws_ext),
students fill out the information and click the Create Account button, then they
can use this account to log in to use.

Note: If you do not fill in the email when registering, the monthly volume is only 2Gb

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
11

3.3. CODEFORCES HANDLE REGISTRATION


Step 1: Open a browser (i.e Chrome), go to Codeforces's account registration page
at: http://codeforces.com/register, then click the Register button as shown below.

Click here
to Register

Step 2: Input log-in information.

Enter Handle (username) according to the following rule: format xxxxxxyyyyT,


where xxxxxx is the six digits of the Class ID, yyyy is the last four digits of the
Student ID, T is the short name of the student. For example, student Lê Quốc Trung
with student ID of 20201010, Class ID of 101020, then the Handle is:
1010201010TrungLQ (refer to the information in the Table below). If your
handle is duplicated, you should have the suffix 1, 2, 3, ... in the back.

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
12

CLASS ID STUDENT ID STUDENT NAME

101020 20201010 Lê Quốc Trung

1010201010TrungLQ
(Write immediately without spaces, note capital letters)

Note:

- Because there is a confirmation step via email, and at the request of HUST, students
must use the HUST e-mail for studying activities.

- If your username is not valid, it will not be approved into the IT1110E subject
practice evaluation system.

Step 3: After clicking Register, there will be notifications as below:

Step 4: Check your registered email to receive notifications and follow the
instructions below to confirm your account registration.

Click the link to


confirm your
email

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
13

The system will then switch to the user interface:

Successfully registered with the


right Handle

3.4. HUST-IT FUNDAMENTAL GROUP MEMBER REGISTRATION


Step1: Access the link of Group below:
https://codeforces.com/group/bveFK04PIR/members
Note: The right Group is Trường ĐH Bách Khoa Hà Nội –– Tin Học Đại Cương

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
14

Step 2: Submit the request to join and wait for approval. Note: students must
name in the correct format to be approved. Students select the membership type as
"Participant" and then click on Join.

Click here to Join the


System

Step 3: Students will wait for approval. After the Admin receives a Join
request to the CodeForces system, if the Handle is valid, the Admin will accept the
request and the student will be a member of the Group of “ĐH Bách Khoa Hà Nội
–– Tin Học Đại Cương”

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
15

Step 4: If you are in the right group, students Click on the ĐH Bách Khoa Hà
Nội –– Tin Học Đại Cương in the Group name column (Picture in step 3) and you
will see the Practice lessons for IT1110E module in CONTESTS (Figure below).
IT1110E-Introduction to Programming-20192 (rectangled in red). Students
attending IT1110E module do not need to care about the other practical exercises.

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
16

3.5. SUBMISSION IN CODEFORCES SYSTEM


Step 1: Login into Codeforces

Step 2: Enter GROUPS and move to Group of ĐH Bách Khoa Hà Nội – Tin
học Đại Cương

Students will see the Practice module of IT1110E-Introduction to


Programming, semester 20xxx. Practice exercises will have a start time (Start) to
suit the student practice schedule.

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
17

Step 3: Students are required to Register to participate (Enter) in Practice


Module. Students must register to be allowed to Submit practical codes.

Click here to register

After Clicking Register as shown in the image above, there will be a notice as
shown below, students Click the Register button (below) to complete the
registration.

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
18

Click here to finish


the registration

When the registration is successful, students will see the status red Register turns
green Registration completed as follows:

From here, students start on IT1110E Practice Exercise and proceed with
submission.

Step 4. Conduct submissions, In tab PROBLEMS, select P1.1 (Demo program)

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
19

Step 5: After clicking on the P1.1 (Demo), it will lead to the problem description

Step 6: In order to submit code to the system, Students click tab of SUBMIT CODE,
then input code into Source code.

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
20

Step 7: Check the status of submission in MY SUBMISSIONS. The Verdict column


will show if the results of the submission have been successful.

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
21

Note: Some notices.


- Perfect result: 100 points means that the test is completely correct and passes all
test cases of the system.
- Compilation error: The program has errors, so students need to correct and submit
again. Students click on the Compilation error to read the error message (all error
messages are in English).

3.6. ANACONDA INSTALLATION

Step 1: Download a file from: https://www.anaconda.com/distribution/


Version: Python 3.7 version 64-bit Graphical Installer (466 MB)

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
22

Step 2: Click and Open this file

The installation display will be presented like this

Step 3: Just click next until this display shows

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
23

Step 4: Complete, click next and finish

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
24

3.7. EXERCISES

P1.1:
Write a program to ask users to enter 2 floating numbers: a and b. Print sum of a
and b.
Type the following code in CodeForces:

Note: Always check input and output format before write a program. The input and
output must have the below format. For example:

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
25

Incorrect input format:

Incorrect output format:

Correct input format:

Correct output format:

Input Output

Float number a
Sum of a and b
Float number b

P1.2:
Write a program that asks the user to type the width and the length of a rectangle
and then outputs to the screen the area and the perimeter of that rectangle.
Note: Always check input and output format before write a program. The input and
output must have the below format.

Input Output

Width W (float number) Area A


Length L (float number) Perimeter P

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
26

P1.3:
Write a program that asks the user to type 5 integers and writes the average of the
5 integers. This program can use only 2 variables.

Input Output

Integer 1st
Integer 2nd
Integer 3rd Average of the 5 integers
Integer 4th
Integer 5th

P1.4:
Write a program that asks the user to type 2 integers A and B and exchange the
value of A and B. Then, the exchanged values will plus with 1. Print the final results.

Input Output

Integer A New Integer A + 1


Integer B New Integer B + 1

P1.5:
Write a program that asks the user to type the price without tax of one kilogram of
tomatoes, the number of kilograms you want to buy and the tax in percent units.
The program must write the total price including taxes.

Input Output

Price without tax of one kilogram


The number of kilograms you want to
Total price including tax
buy
Tax (in \%)

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
27

4. PRACTICE EXERCISES NUMBER 2

P2.1:

Read positive numbers and print the average between them when you type a
number smaller than 1. If at the first time, you input a number smaller than 1,
output print ‘0’.

Input Output

Positive float number 1st


Positive float number 2nd
Positive float number 3rd
Positive float number 4th 0 or Average of number 1st to nth
….
Positive float number nth
1

Note: You do not know precisely n.

P2.2:

Write a Python program to convert temperatures to and from Celsius, Fahrenheit.

Enter Temperature T, Type of T (C or F). Convert to different type: If type is C, T


convert to F. If type is F, T convert to C. Print new T and type of new T

Note: Formula: c/5=f-32/9 [where c = temperature in Celsius and f = temperature


in Fahrenheit]

Input Output

T New T
C or F C or F

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
28

P2.3:
Write a program that asks the user to type the value of N and compute N!
Note: In this exercise, you must use loop to solve this problem. Do not use library
math of Python.

Input Output

Integer number N N!

P2.4:

Write a program that asks the user to type the values of x and n and compute the
following expressions: import math to calculate factorial

a)

𝑆 = √𝑥 + √𝑥 + √𝑥 + √𝑥 + ⋯ + √𝑥, 𝑛 𝑠𝑞𝑢𝑎𝑟𝑒 𝑟𝑜𝑜𝑡 𝑠𝑖𝑔𝑛𝑠

b) 𝑥2 𝑥3 𝑥𝑛
𝑆 = 1 + 𝑥 + + + ⋯+
2 3 𝑛

c) 𝑥2 𝑥3 𝑥𝑛
𝑆 =1+𝑥+ + + ⋯+
2! 3! 𝑛!

d) 𝑥2 𝑥3 (−1)𝑛 𝑥 𝑛
𝑆 = 1 − 𝑥 + − + ⋯+
2! 3! 𝑛!

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
29

Note: In this exercise, you use library math by the following python code:
import math;
For example:
To calculate square root: math.sqrt(x)
To calculate factorial: math.factorial(x)

Input Output

S part a
Float number x S part b
Integer number n S part c
S part d

P2.5:
Write a program that asks the user to type an integer N and that indicates if N is a
prime number or not. ‘1’ is true, ‘0’ is false.
Note:
▪ To have better solution, you should minimize a number of loop in use as
possible.
▪ Do not use libraries.

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
30

5. PRACTICE EXERCISES NUMBER 3

P 3.1:

Write a Python function that takes a positive integer n as an argument and returns
the largest power of 2 less than or equal to n.

Input Output

the largest power of 2 less than or


Positive integer n
equal to n

P 3.2:

Write function prime that indicates an integer N is a prime number or not (return
1 if N is prime and 0 otherwise)

Check if a prime number can be expressed as sum of two prime numbers. If yes,
print ‘1’. If no, print ‘0’. Print the two prime numbers

Note: Do not use python library.

Input Output

0 or 1
Integer N Prime number 1st
Prime number 2nd

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
31

P3.3:

Write a function to calculate the following function


cos 4.5𝑥 2 + 5 sin(𝑥 3 − 1) 𝑖𝑓 𝑥 < 0
𝑓 (𝑥 ) = { 7 𝑖𝑓 𝑥 = 0
log 2 𝑥 + √𝑥 2 + 5 if x > 0
Input m intergers. Calculate the values of f with the inputs. Print out their sum.

Input Output

Integer 1st
Integer 2nd
Integer 3rd Sum of f(1st)+f(2nd)+…+f(mth)
….
Integer mth

Note: Using library math of python to calculate sine, cosine, and logarithm.

P3.4:

Given a mathematical function H(x, y) defined as follows


3𝑥 2 − ln 𝑦 𝑖𝑓 𝑥 < 𝑦 − 2
𝑥+𝑦
𝐻 (𝑥, 𝑦) = { + 8 𝑖𝑓 𝑦 − 2 ≤ 𝑥 ≤ 𝑦 + 2
2
𝑦 3 + 2 sin 𝑥 𝑖𝑓 𝑥 > 𝑦 + 2

Write a Python function to compute 𝐻 (𝑥, 𝑦) that receives 2 real numbers x, y.


Compute 𝐻(𝑥, 𝑦) with the following inputs:
(−2, 5), (−1.5, 4), (−1, 3), … , (5, −9), (5.5, 10), (6, 11) (the difference between 2
successive x is 0.5, between 2 successive y is -1). Print all the outputs.

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
32

Input Output

H(x,y)
H(-2,5)
Float number x H(-1.5,4)
Float number y H(-1,3)
….
H(6,11)

P3.5:

Write a Python program to find the roots of quadratic equation:


𝑎𝑥 2 + 𝑏𝑥 + 𝑐 = 0

Input Output

a
b
“No roots” or roots of function
c

Note:
▪ Solve equation in both cases: a = 0 and has complex roots.
▪ If there are not roots, print out a string: “no roots”.
▪ If it has roots, print out those roots.

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
33

6. PRACTICE EXERCISES NUMBER 4


P4.1:

Write a program that takes two strings r, s. Print out “1” if the second string s
contained within the first. Otherwise, print out ‘0’.

Input Output

String r
1 or 0
String s

P4.2:

Write a program to reverse words in a given string in python.


For example: “Advanced Program AI” -> “AI Program Advanced”.

Input Output

A given string s Reverse of the given string s

Note: You should use some python methods with string like join() or spilt().

P4.3:

Write a program which asks you to enter a string and an integer number N. The
program shortens your string to N characters. If the string is already shorter than
N, the program should not change the string. Print out the string.

Input Output

A given string s
Required String
An integer number N

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
34

P4.4:

Write a program which asks you to enter two strings s and t, an integer number n.
The program prints the position of the first occurrence of t within a substring of s.
n is the position where the substring begins. If t is not found in the substring of s,
the program prints 0

For example, if s is "avbprogramvb", t is "vb" and n is 4. Substring of s is


“programvb” the program prints 1.

Input Output

String s
Position of the first occurrence of t
String t
within a substring of s or 0
Integer number n

P4.5:

Write a program that takes two strings. Print out the number of times that each
character appears in both of them and the characters found?

Input Output

Character 1st found


Number of time character 1st appears
Character 2nd found
Number of time character 2nd appears
String s
Character 3rd found
String t
Number of time character 3rd appears
….
Character nth found
Number of time character nth appears

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
35

7. PRACTICE EXERCISES NUMBER 5


P5.1:
Write a program that read n float numbers into a list A. Enter an integer number k.
Create a new list B is as same as list A. Then, add one float element m before the kth element
in list B. Sort the list B in ascending order. Print list A and list B.

Input Output

Element 1st List A


Float number 1st
Element 2nd List A
Float number 2nd

Float number 3rd
Element nth List A

Element 1st List B
Float number nth
Element 2nd List B
Integer k

Float number m
Element n+1th List B

P5.2:

Write a Python program to enter input elements of list from the keyboard
and find Cumulative sum of a list. Print out the results.
For example: [10, 20, 30, 40, 50] -> [10, 30, 60, 100, 150]
[2, 5, 8, 12] -> [2, 7, 15, 27].

Input Output

Element 1st Element 1st of cumulative sum


Element 2nd Element 2nd of cumulative sum
Element 3rd Element 3rd of cumulative sum
… ….
Element nth Element nth of cumulative sum

P5.3:

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E
36

Write a Python program to find the greatest common divisor (gcd) of two integers.
Note: Must use recursion.

Input Output

Integer a
The greatest common divisor
Integer b

P5.4:
Write a Python program to enter input elements of list from the keyboard,
find the most frequent element in it. If there are multiple elements that appear
maximum number of times, print any one of them.

Input Output

Element 1st
Element 2nd
Maximum frequency
Element 3rd
Element has the maximum frequency

Element nth

P5.5:
Write a Python program to count the occurrences of an integer K in an sorted list.
Enter integer numbers in sorted order in list. Enter integer K. Print out the
occurrences of K.
Input Output

integer number 1st


integer number 2nd
integer number 3rd
The number of occurrences

integer number nth
Integer k

PRACTICE GUIDELINE DOCUMENT


© 2020 – HUST – SOICT
INTRODUCTION TO PROGRAMMING - IT1110E

You might also like