0% found this document useful (0 votes)
8 views

IE2108 Tutorial 01

This document is a tutorial for the IE2108 Data Structures and Algorithms in Python course at Nanyang Technological University. It includes a series of programming tasks to be completed using Jupyter Notebook, such as creating and manipulating variables, lists, and dictionaries, as well as implementing basic algorithms and games. The tutorial aims to help students practice Python programming and understand fundamental data structures and algorithms.

Uploaded by

Brian lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

IE2108 Tutorial 01

This document is a tutorial for the IE2108 Data Structures and Algorithms in Python course at Nanyang Technological University. It includes a series of programming tasks to be completed using Jupyter Notebook, such as creating and manipulating variables, lists, and dictionaries, as well as implementing basic algorithms and games. The tutorial aims to help students practice Python programming and understand fundamental data structures and algorithms.

Uploaded by

Brian lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

NANYANG TECHNOLOGICAL UNIVERSITY

School of Electrical & Electronic Engineering

IE2108 Data Structures and Algorithms in Python

Tutorial No. 01 (Sem 1, AY2023-2024)

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:

----

Create the following variables:

p = "Hello Singapore!"

pp = "I'm learning Python."

q = 10

r = 10.2

----

Display the variables, just make sure the variables are as what I expect.

----

Display the data type (or class) of each variable.

----

Display p + pp .

----

Display q + r .

----

Display range(10) .

----

Display list(range(10)) .

----

Modify the above statement to display [1, 3, 5, 7, 9].

----

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'.

Display it to make sure that your command worked.

----

Append a number 32 to the end of the list and verify your command works.

----

What is the meaning of b[2:3]?

----

Remove the 3rd element of the list.

----

Use a different command to remove the 1st element of the list.

----

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

----

What data type is person defined below?

person = {}

----

Display person after the following.

2
person['firstname'] = 'Jacky'

person['lastname'] = 'Chan'

person['age'] = 69

person['address'] = ['Hong Kong']

----

Display his first name.

----

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

you guess it right.

Hint: Use the following:

import random (for importing a library on random numbers)

random.randint(1, 100) (for generating a random integer between 1 and 100, including both 1 and
100 themselves.)

----

Generate and print the first n numbers in the Fibonacci sequence

which is 0, 1, ..., with each subsequent number equal to the sum of

the previous 2 numbers.

----

Check if a given string is a palindrome (reads the same forwards and backwards).

----

You might also like