IE2108 Tutorial 01
IE2108 Tutorial 01
Before attempting these problems, please install Jupyter Notebook (see installation instructions at
the end of Week 1 Lecture Notes). In Jupyter Notebook, write and run python programs to do the
following:
----
p = "Hello Singapore!"
q = 10
r = 10.2
----
Display the variables, just make sure the variables are as what I expect.
----
----
Display p + pp .
----
Display q + r .
----
Display range(10) .
----
Display list(range(10)) .
----
----
1
Modify the above statement to display [20, 18, 16, 14, 12].
----
Create a list b with the following elements: 'data', 'and', 'book', 'structure', 'hello', 'st'.
----
Append a number 32 to the end of the list and verify your command works.
----
----
----
----
Display the number of elements in the list (the length of the list).
----
For the following 2 values, check whether both are greater than 0
a = 32
b = 132
----
For the following 2 values, check whether at least one is greater than 0.
a = 32
b = -32
----
person = {}
----
2
person['firstname'] = 'Jacky'
person['lastname'] = 'Chan'
person['age'] = 69
----
----
Write a basic calculator that performs addition, subtraction, multiplication, and division.
----
Write a simple game where the user tries to guess a randomly generated number.
The program first selects a random number without telling you the number.
You make a guess. The program will tell you if too high or too low, until
random.randint(1, 100) (for generating a random integer between 1 and 100, including both 1 and
100 themselves.)
----
----
Check if a given string is a palindrome (reads the same forwards and backwards).
----