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

Exercises_Answers

Uploaded by

Kasun Madusanka
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)
2 views

Exercises_Answers

Uploaded by

Kasun Madusanka
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/ 8

Development Programme 2020 – Introduction to Programming

Exercises - Answers

1. Write a program to draw a pattern like this.


Hint: Learn how you can print a line without inserting a newline.

2. Write a program to add numbers between 1 and N where N is defined by the user input.
Hint: Search the documentation for range
(https://docs.python.org/3/library/stdtypes.html#typesseq)

3. Write a program to draw a shape like this.


Hint: The formula for finding the sum of the measure of the interior angles is (n - 2) * 180.
To find the measure of one interior angle, we take that formula and divide by the number of
sides n: (n - 2) * 180 / n

4. Draw the art in following figure using turtle. You can use turtle.circle() function to draw
circles.
Hint: There are 30 circles in the figure
5. Create a random list of size N with integer random numbers in the rang 0-9 . N should be an
input given by the user.
Display the random number list and the same list in reverse order.
Hint: Have a quick look at the Python random module
(https://docs.python.org/3/library/random.html)

Also read following documentation on Python lists. You don’t have to read all the details. In this case
find out how you can append elements and reverse the elements of a list in place.

https://docs.python.org/3/tutorial/datastructures.html

6. Input N integers from user and store them in a List. Display the list and the average of those
N numbers.
7. The exponential function ex can be characterized in a variety of equivalent ways. In
particular, it may be defined by the following series.

Calculate the value of ex by adding first 100 terms of this series.

Hint: Use the math module. Look for its documentation and check how you can calculate factorial of
a number.

8. Write a function which returns the value of the following function for a given x value.
9. Write a program that asks the age of the user and display the age category depending on age.
10. Analyse the following code that implements a simple game.
Improve the code to incorporate 3 players.
Please read online how you can implement a while loop in Python
11. Write a code to create an Image like this!

You might also like