Exam Practice
Exam Practice
Enter base: 20
Enter height: 10
The area of the triangle is 100
5. Write a script that prompts the user to enter side a, side b, and side c of the
triangle. Calculate the perimeter of the triangle (perimeter = a + b + c).
Enter side a: 5
Enter side b: 4
Enter side c: 3
The perimeter of the triangle is 12
6. Get length and width of a rectangle using prompt. Calculate its area (area =
length x width) and perimeter (perimeter = 2 x (length + width))
7. Get radius of a circle using prompt. Calculate the area (area = pi x r x r) and
circumference (c = 2 x pi x r) where pi = 3.14.
8. Calculate the slope, x-intercept and y-intercept of y = 2x -2
9. Slope is (m = y2-y1/x2-x1). Find the slope and Euclidean distance between point
(2, 2) and point (6,10)
10. Compare the slopes in tasks 8 and 9.
11. Calculate the value of y (y = x^2 + 6x + 9). Try to use different x values and figure
out at what x value y is going to be 0.
12. Find the length of 'python' and 'dragon' and make a falsy comparison statement.
13. Use and operator to check if 'on' is found in both 'python' and 'dragon'
14. I hope this course is not full of jargon. Use in operator to check if jargon is in the
sentence.
15. There is no 'on' in both dragon and python
16. Find the length of the text python and convert the value to float and convert it to
string
17. Even numbers are divisible by 2 and the remainder is zero. How do you check if
a number is even or not using python?
18. Check if the floor division of 7 by 3 is equal to the int converted value of 2.7.
19. Check if type of '10' is equal to type of 10
20. Check if int('9.8') is equal to 10
21. Writ a script that prompts the user to enter hours and rate per hour. Calculate pay
of the person?
Enter hours: 40
Enter rate per hour: 28
Your weekly earning is 1120
22. Write a script that prompts the user to enter number of years. Calculate the
number of seconds a person can live. Assume a person can live hundred years
==================================================================
1. Concatenate the string 'Thirty', 'Days', 'Of', 'Python' to a single string, 'Thirty Days
Of Python'.
2. Concatenate the string 'Coding', 'For' , 'All' to a single string, 'Coding For All'.
3. Declare a variable named company and assign it to an initial value "Coding For
All".
4. Print the variable company using print().
5. Print the length of the company string using len() method and print().
6. Change all the characters to uppercase letters using upper() method.
7. Change all the characters to lowercase letters using lower() method.
8. Use capitalize(), title(), swapcase() methods to format the value of the string
Coding For All.
9. Cut(slice) out the first word of Coding For All string.
10. Check if Coding For All string contains a word Coding using the method index,
find or other methods.
11. Replace the word coding in the string 'Coding For All' to Python.
12. Change Python for Everyone to Python for All using the replace method or other
methods.
13. Split the string 'Coding For All' using space as the separator (split()) .
14. "Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon" split the string at the
comma.
15. What is the character at index 0 in the string Coding For All.
16. What is the last index of the string Coding For All.
17. What character is at index 10 in "Coding For All" string.
18. Create an acronym or an abbreviation for the name 'Python For Everyone'.
19. Create an acronym or an abbreviation for the name 'Coding For All'.
20. Use index to determine the position of the first occurrence of C in Coding For All.
21. Use index to determine the position of the first occurrence of F in Coding For All.
22. Use rfind to determine the position of the last occurrence of l in Coding For All
People.
23. Use index or find to find the position of the first occurrence of the word 'because'
in the following sentence: 'You cannot end a sentence with because because
because is a conjunction'
24. Use rindex to find the position of the last occurrence of the word because in the
following sentence: 'You cannot end a sentence with because because because
is a conjunction'
25. Slice out the phrase 'because because because' in the following sentence: 'You
cannot end a sentence with because because because is a conjunction'
26. Find the position of the first occurrence of the word 'because' in the following
sentence: 'You cannot end a sentence with because because because is a
conjunction'
27. Slice out the phrase 'because because because' in the following sentence: 'You
cannot end a sentence with because because because is a conjunction'
28. Does ''Coding For All' start with a substring Coding?
29. Does 'Coding For All' end with a substring coding?
30. ' Coding For All ' , remove the left and right trailing spaces in the given
string.
31. Which one of the following variables return True when we use the method
isidentifier():
○ 30DaysOfPython
○ thirty_days_of_python
32. The following list contains the names of some of python libraries: ['Django',
'Flask', 'Bottle', 'Pyramid', 'Falcon']. Join the list with a hash with space string.
Use the new line escape sequence to separate the following sentences.
I am enjoying this challenge.
33. I just wonder what is next.
radius = 10
area = 3.14 * radius ** 2
The area of a circle with radius 10 is 314 meters square.
8 + 6 = 14
8 - 6 = 2
8 * 6 = 48
8 / 6 = 1.33
8 % 6 = 2
8 // 6 = 1
8 ** 6 = 262144
==================================================================
Exercises: Level 1
1. Declare an empty list
2. Declare a list with more than 5 items
3. Find the length of your list
4. Get the first item, the middle item and the last item of the list
5. Declare a list called mixed_data_types, put your(name, age, height, marital
status, address)
6. Declare a list variable named it_companies and assign initial values Facebook,
Google, Microsoft, Apple, IBM, Oracle and Amazon.
7. Print the list using print()
8. Print the number of companies in the list
9. Print the first, middle and last company
10. Print the list after modifying one of the companies
11. Add an IT company to it_companies
12. Insert an IT company in the middle of the companies list
13. Change one of the it_companies names to uppercase (IBM excluded!)
14. Join the it_companies with a string '#; '
15. Check if a certain company exists in the it_companies list.
16. Sort the list using sort() method
17. Reverse the list in descending order using reverse() method
18. Slice out the first 3 companies from the list
19. Slice out the last 3 companies from the list
20. Slice out the middle IT company or companies from the list
21. Remove the first IT company from the list
22. Remove the middle IT company or companies from the list
23. Remove the last IT company from the list
24. Remove all IT companies from the list
25. Destroy the IT companies list
ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24]
● Sort the list and find the min and max age
● Add the min age and the max age again to the list
● Find the median age (one middle item or two middle items divided by two)
● Find the average age (sum of all items divided by their number )
● Find the range of the ages (max minus min)
● Compare the value of (min - average) and (max - average), use abs() method
1. Find the middle country(ies) in the countries list
2. Divide the countries list into two equal lists if it is even if not one more country for
the first half.
3. ['China', 'Russia', 'USA', 'Finland', 'Sweden', 'Norway', 'Denmark']. Unpack the
first three countries and the rest as scandic countries.
==================================================================
Exercises: Level 1
1. Create an empty tuple
2. Create a tuple containing names of your sisters and your brothers (imaginary
siblings are fine)
3. Join brothers and sisters tuples and assign it to siblings
4. How many siblings do you have?
5. Modify the siblings tuple and add the name of your father and mother and assign
it to family_members
Exercises: Level 2
1. Unpack siblings and parents from family_members
2. Create fruits, vegetables and animal products tuples. Join the three tuples and
assign it to a variable called food_stuff_tp.
3. Change the about food_stuff_tp tuple to a food_stuff_lt list
4. Slice out the middle item or items from the food_stuff_tp tuple or food_stuff_lt list.
5. Slice out the first three items and the last three items from food_staff_lt list
6. Delete the food_staff_tp tuple completely
7. Check if an item exists in tuple:
● Check if 'Estonia' is a nordic country
● Check if 'Iceland' is a nordic country
nordic_countries = ('Denmark', 'Finland','Iceland', 'Norway', 'Sweden')
==================================================================
Exercises: Level 1
1. Find the length of the set it_companies
2. Add 'Twitter' to it_companies
3. Insert multiple IT companies at once to the set it_companies
4. Remove one of the companies from the set it_companies
5. What is the difference between remove and discard
Exercises: Level 2
1. Join A and B
2. Find A intersection B
3. Is A subset of B
4. Are A and B disjoint sets
5. Join A with B and B with A
6. What is the symmetric difference between A and B
7. Delete the sets completely
Exercises: Level 3
1. Convert the ages to a set and compare the length of the list and the set, which
one is bigger?
2. Explain the difference between the following data types: string, list, tuple and set
3. I am a teacher and I love to inspire and teach people. How many unique words
have been used in the sentence? Use the split methods and set to get the unique
words.
==================================================================
1. Create an empty dictionary called dog
2. Add name, color, breed, legs, age to the dog dictionary
3. Create a student dictionary and add first_name, last_name, gender, age, marital
status, skills, country, city and address as keys for the dictionary
4. Get the length of the student dictionary
5. Get the value of skills and check the data type, it should be a list
6. Modify the skills values by adding one or two skills
7. Get the dictionary keys as a list
8. Get the dictionary values as a list
9. Change the dictionary to a list of tuples using items() method
10. Delete one of the items in the dictionary
11. Delete one of the dictionaries
==================================================================