Workshop 4 (Python)
Workshop 4 (Python)
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
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.
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.
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