Python Excercises
Python Excercises
Use the internet and provided cheat sheets to do the following problems:
Write python program to:
1. Compute the perimeter and area of the circle with radius =10
2. Swap the contents of two variables a, b with given values, namely
12, 39
3. Find the largest values among two given variables a, b with given
values, namely 34, 78
4. Test whether a number is divisible by 5 or 6 or both
e.g. 150 is divisible by 5 and 6, 15 is divisible by 5, 12 is divisible
by 6 and 41 is neither divisible by 5 nor 6.
5. Calculate number of days between two dates
(Hint: >>> from datetime import date then use function
date(yy,mm,dd) to create a datetime value).
6. Calculate the number of living days from your birthday.
(Hint: use date.today() to get current date)
7. Print a table of squares and cubes as shown on the right:
(Hint: print (‘{0:2d {1:3d} ‘.format(x,y) will display x,y like a string with the width of 2
and 3 characters respectively)
8. Test whether a letter is a vowel or not
(hint: make use of tenary operator expression
value_when_true if condition else value_when_false )
9. Print a line of asterisk (*) characters:
10. Print a rectangular of asterisk (*) character of m rows and n columns