[Solved] COMP1007 Assignment1-Python Concepts

$25

File Name: COMP1007_Assignment1-Python_Concepts.zip
File Size: 339.12 KB

SKU: [Solved] COMP1007 Assignment1-Python Concepts Category: Tag:
5/5 - (1 vote)

Remark: Please try to answer the questions in Part 1 without running the codes in a real Python environment. You can review the lab sheet to refresh the basic Python concepts before you work on these questions.

  1. Fill in the correct Python data type (such as int, float, str, bool, tuple, list, dict) for the following data items:
Data Item Data Type
COMP1007
3.14159
(Jack, 174.0, 62.0, 65789084)
[Jack, 174.0, 62.0, 65789084]
False
False
‘Hi, I am Jack!
1000
{0:A, 1:B, 2:C}
([a, b, c], (1, 2, 3))
  1. Which of the following Python statements are wrong?
Python statements Correct () or Wrong ( X )
PI = 3.14159
True = 1
TRUE = 1
x = (a, b, c) x[0] = d
x = [a, b, c] x[0] = d
  1. What will be the output of the following Python statements?
Python statements Output
x = (5, 7, 9, 11) print(x[3])
y = range(-5, 5, 2) print(list(y))
myList = [10, 20, 30, 40] myList.insert(2, 50) print(myList)
name = [Tom, Ada, Jack, Zoe] name.sort() print(name)
dict = {001:Tom, 002:Ada, 003:Jack} dict[002] = Zoe print(dict)

Part 2: Python Programming

  1. Write a segment of Python statements that does the followings:

(1) To prompt the user to input his/her name and read in the name; (2) To prompt the user to input his/her age and read in the age;

(3) Show a message that includes the users name and age. An example output of the program is given as follows:

Please input your name: CHAN DAI MAN

Please input your age: 30

Hello, CHAN DAI MAN! You are 30 years old.

In the above example, CHAN DAI MAN and 30 are typed in by the user.

Write your Python program here:

  1. Write a segment of Python statements that does the followings:
  • To generate a range myRange that includes the following integers: -100, -96, -92, , 0, 4, 8, , 96, 100.
  • To generate a list myList from myRange. So myList should also include the integers -100, -96, -92, , 0, 4, 8, , 96, 100.
  • To generate a slice mySlice by slicing from myList, such that mySlice includes the integers 0, 4, 8, , 96, 100.
  • To generate a slice myNewSlice by slicing from myList, such that myNewSlice includes the integers 0, 8, 16, 24, , 96.

Write your Python program here:

  1. In this problem, you are required to design a key-value pair structure that can store the useful information of a store in a shopping mall, such as name, contact phone number, and opening hours. You can design a store ID as the key. In your Python program, please create a dictionary to store the information (i.e., key-value pairs) of at least four stores. Then please prompt the user to input a store ID, and your program should then output the contact phone number of that store. We assume the user always inputs a valid store ID.

Write your Python program here:

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] COMP1007 Assignment1-Python Concepts
$25