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

Workshop 4 (Python)

The document provides a series of Python exercises focused on basic programming concepts. It includes tasks such as calculating the area of a circle, finding maximum and minimum values without built-in functions, and determining the number of regions formed by straight lines. Each exercise includes a sample program and expected output to guide the user.

Uploaded by

khkoo
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)
5 views

Workshop 4 (Python)

The document provides a series of Python exercises focused on basic programming concepts. It includes tasks such as calculating the area of a circle, finding maximum and minimum values without built-in functions, and determining the number of regions formed by straight lines. Each exercise includes a sample program and expected output to guide the user.

Uploaded by

khkoo
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

Python 3 – Extra Exercise 1 (Basics)

Reference:
https://www.w3resource.com/python-exercises/python-basic-exercises.php
https://www.w3resource.com/python-exercises/basic/

1. Write a Python program which accepts the radius of a circle from the user and

compute the area.

Program
from math import pi
#to be completed

Sample Output
Input the radius of the circle: 1.1
The area of the circle with radius 1.1 is: 3.8013271108436504
2. Write a Python program to display the first and last colors from the following list.

Program
color_list = ["Red","Green","White" ,"Black"]

Sample Output
Red Black
3. Write a Python function to find the maximum and minimum numbers from a
sequence of numbers. Go to the editor
* Note: Do not use built-in functions.

Program
def max_min(data):
#to be completed
print(max_min([0, 10, 15, 40, -5, 42, 17, 28, 75]))

Sample Output
(75, -5)
4. Write a Python program to cut out words of 3 to 6 characters length from a given
sentence not more than 1024 characters.

Program
print("Input a sentence (1024 characters. max.)")
#to be completed

Sample Input
English sentences consisting of delimiters and alphanumeric characters are given
on one line

Sample Output
Input a sentence (1024 characters. max.)
This is a quick checking of the program
3 to 6 characters’ length of words:
This is a quick of the
5. if you draw a straight line on a plane, the plane is divided into two regions. For
example, if you pull two straight lines in parallel, you get three areas, and if you
draw vertically one to the other you get 4 areas.

Write a Python program to create maximum number of regions obtained by


drawing n given straight lines.

Program
while True:
print("Input number of straight lines (o to exit): ")
#to be completed
print("Number of regions:")
print((n*n+n+2)//2)

Sample Input
5

Sample Output
Input number of straight lines (o to exit):
5
Number of regions:
16
6. Write a Python function that takes a sequence of numbers and determines if all
the numbers are different from each other.

Program
def test_distinct(data):
#to be completed
print(test_distinct([1,5,7,9]))
print(test_distinct([2,4,5,5,7,9]))

Hint
set() creates a set object. The items in a set list are unordered, so it will appear in
random order and no duplicates, and it returns:
> an empty set if no parameters are passed
7. Write a Python program to find the number of notes (Sample of notes: 10, 20, 50,
100, 200 and 500 ) against an given amount.

Range - Number of notes(n) : n (1 ≤ n ≤ 1000000).

Program
def no_notes(a):
#to be completed
print(no_notes(880))
print(no_notes(1000))

Sample Output
6
2
8. Write a Python program to compute the digit number of sum of two given
integers.

Each test case consists of two non-negative integers x and y which are separated
by a space in a line.
0 ≤ x, y ≤ 1,000,000

Program
print("Input two integers(a b): ")
#to be completed

Sample Input
57

Sample Output
Input two integers(a b):
57
Number of digit of a and b.:
2

You might also like