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

Python Exersises

The document outlines a series of Python programming exercises designed for students at Turin Polytechnic University in Tashkent. Each lesson includes specific tasks, such as installing Python, writing simple programs, and understanding concepts like variables and data types. The exercises progress in complexity, culminating in topics such as program design, testing, and object reference.

Uploaded by

gabrielmofor45
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python Exersises

The document outlines a series of Python programming exercises designed for students at Turin Polytechnic University in Tashkent. Each lesson includes specific tasks, such as installing Python, writing simple programs, and understanding concepts like variables and data types. The exercises progress in complexity, culminating in topics such as program design, testing, and object reference.

Uploaded by

gabrielmofor45
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

TURIN POLYTECHNIC UNIVERSITY IN TASHKENT

AUTOMATIC CONTROL AND COMPUTER ENGINEERING DEPARTMENT

Python programming Exercises

Autor: Dr. N.Mahamatov


Lesson 1 Exercise (Python 3 Download and Installation)

1. Download and Install Python (https://www.python.org/)

2. Launch the Python Command line

3. Launch the Python GUI

END
Lesson 2 Exercise ("Hello World" (Python 3 Command Line))

1. Launch the Python (command line)

2. Enter the two lines as shown below

 What output do you expect?

 What output did you get?

END
Lesson 3 Exercise (“Hello World” (Python GUI))

1. Launch the Python GUI

2. Select New Window

3. Enter the code as shown below

4. Run the program by pressing F5 or select as shown below (remember to save


the program with a sensible name)

 What output do you expect?


 What output did you get?

5. Amend the program implemented at step 4 so that it outputs your full name
instead of "Hello World"

6. Amend the program again so that it so that it outputs your full name on one
line and your age on the line below.

7. Again amend the program so it outputs your age first and then your full
name on the next line.

END
Lesson 4 Exercise (Python Keyboard Input)
1. Open up the Python GUI and enter the program shown below:

2. Run the program and you should see the following screenshot.

In response to the user friendly prompt enter the following text.

He's not the Messiah, he's a very naughty boy!

What was the program output?

3. Amend the program as requested below then save and run the program

Did the program still work?

4. Write a program that asks a user to enter their name (use an input function).
Then have it ask for the first line of their address (use another input
function). Display their name on one line and their address on the next line.

END
Lesson 5 Exercise (Python Program Design)

1. Without looking back at the video consider the following specification.

Develop a program that calculates an individual’s gross pay.

As part of the program development process produce each of the


followingartefacts i.e. start to design the program.

1. Data Table
2. Algorithm

The format of the Data Table is shown below:

2. Consider the following specification.

Write a program that calculates the area of a rectangle.

area = width x height

For this specification produce a:

1. Data Table

2. Algorithm

NOTE: You decide on the units of measurements for width, height etc.
(e.g.inches, cm, mm etc).

END
Lesson 6 Exercise (Coding a Design in Python)
1. For the Algorithm and Data Table below implement the Python program
i.e. type it into the editor and run the program.

2. Implement the design for calculating the area you completed in the
lastexercise.

END
Lesson 7 Exercise (Testing a Python Program)
1. For the program on calculating an employee’s gross-pay (developed in the
last exercise) devis

2. e a suitable simple test plan and test the program againstthis test plan. A
partly complete simple test plan is shown below:

3. For the program on calculating the area of a rectangle (developed in the last
exercise) devise a suitable simple test plan and test the program against
thistest plan. A suitable template for a simple test plan is shown below you
mustdecide on what the inputs are (two input columns have been included
which should be a hint).

END
Lesson 8 Exercise (Python Variables and Data Types)
1. Fill in the blank for the following description of a program variable:

Program variables are reserved locations used to store data

2. In your own words describe what is meant by a variable identifier and a


variable value.

3. Program variables have data types such as: Integer; Float and String. After
the execution of the following snippet of code what are the data type of the
three variables var_one, var_two and var_three?

4. Run the code snippet below to assist you with the answer to the question
above (i.e. Step 4). Note type(var_one) 'reports' the type of the variable in
its brackets.

5. The Data type of a variable defines the way in which the variable can be
processed. With this in mind what will happen when the following snippet of
code is executed.

6. Enter and run the code shown above to check your answer to question 6

7. Enter and run the code shown below did it work in the way you expected?
Lesson 9 Exercise (Python Assignment Statement)
1. What is output to the visual display unit (VDU) by the following snippet
ofcode?

2. Confirm your answer by entering and running the program shown above

3. What is output to the visual display unit (VDU) by the following snippet
ofcode?

4. Confirm your answer by entering and running the program shown above.

5. What is output to the visual display unit (VDU) by the following snippet
ofcode?

6. Confirm your answer by entering and running the program shown above.

END
Lesson 10 Exercise (Python Assignment Operators)
1. What is the output from the following program?

2. What is the output from the following program?

3. What is the output from the following program?

4. What is the output from the following program? Please note the negative
value of the variable y.

5. What is the output from the following program?


6. Check your own workings to the questions outlined in steps 2 to 6 by
entering each program in turn and running each program to see if the actual
output is as you predicted.

END
Lesson 11 Exercise (Augmented Assignment Operators)
1. What is the output of the following program?

2. What is the output of the following program?

3. What is the output of the following program? Please note the negative value
of the variable y.

4. What is the output of the following program?

5. Check your own answers to questions 2 to 5 by entering and running each


program in turn to see if the actual output is as you predicted.

END
Lesson 12 Exercise (Naming Variables)
1. How would you alter the following program to ensure it was consistent with
the recommendations for variable identifiers (as recommended in the video)?

2. The following program will calculate the gross pay from the hours worked and
rate of pay per hour entered by a user of the program. How would you
amend the program to ensure it met the recommendations outlined in the
video?

3. For the program above give reasons why the choice of the variable identifiers
used in the program are not advised.
4. Listed below are snippets of Python code which snippets contain variable
identifiers that ‘will not work’ (i.e. which are illegal)?

END
Lesson 13 Exercise (Case Sensitivity)
1. How would you alter each the following program ‘snippets’ to ensure they
were consistent with the ‘case sensitivity’ recommendations for variable
identifiers (as recommended in the video)?

2. Predict the runtime for each of the program snippets above. Check your
answers by entering the code EXACTLY as shown above and run each to
check your answer.

END
Lesson 14 Exercise (A Python Variable versus a Python Object)
1. Draw the 'execution space' when the followingline of code executes.

2. Draw the 'execution space' when the followinglines of code execute.

END

Lesson 15 Exercise (An Immutable Object)

1. Draw a sequence of diagrams showing the 'execution space' when the


following lines of code execute.

2. Make sure you show, in one of the diagrams of the sequence, the
garbagecollection of an appropriate object.

3. Describe what is meant by immutable.

4. What is achieved by garbage collection?

END
Lesson 16 Exercise (Pythons Object Reference)

1. Ensure you have viewed the video (associated with this exercise) at this link.

If you are viewing a printed copy of this exercise locate the video on the
YouTube channel either directly on the channel or via the supporting website.

2. Compare and contrast the two models as outlined in the video i.e.
the‘simple’ model and the ‘execution space’ model.

3. Draw a sequence of diagrams that represent the ‘simple’ model for


theexecution of the following program.

4. Draw a sequence of diagrams that represent the ‘execution space’ model


forthe execution of the above program.

END

You might also like