2 min to read
Coding 101 - Exercises
This article is a part of the Python - 101 series, you can access the full version of the series here:
-
Coding 101
- Introduction
- Coding 101 - exercises (you are here!)
-
Writing functions in Python
-
Control flows in Python
-
Errors and exceptions
-
Classes
Welcome to the second article of the Coding 101 series. Now you have known the basic of Python and R, it’s time to put your skills into some practice.
1. Using Python and R as a calculator
- The volume of a sphere with radius r is 43 πr^3. What is the volume of a sphere with radius 5?
- Suppose the cover price of a book is $24.95, but bookstores get a 40% discount. Shipping costs $3 for the first copy and 75 cents for each additional copy. What is the total wholesale cost for 60 copies?
- If I leave my house at 6:52 am and run 1 mile at an easy pace (8:15 per mile), then 3 miles at tempo (7:12 per mile) and 1 mile at an easy pace again, what time do I get home for breakfast?
2. Basic problems around data types
- Create a list (Python)/vector (R) containing the names of the following countries: Vietnam, United Kingdom, United States, Australia, New Zealand. Remember to keep the same order. Repeat that list/vector two times to create another list/vector, i.e. contain two Vietnam, two United Kingdom, etc.
- Using that list/vector, create a new list/vector and returns a new list/vector that contains all but the first and last elements
- A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward. Reverse a word to check if one is a palindrome. Can it be done in Python or R? Example: race car, madam
-
Check if there is any element that appears more than once in a list/vector. Which data types would you use in this situation? Example:
- Python: [1,4,6,11,4]
- R: c(1,4,6,11,4)
That’s all for today. Come back for another challenge tomorrow! Comment below or direct me the link to your answer, I will try my best to review it and send back to you privately. As a tip, you should compile it to a script, it would me much more pleasing for me when viewing it.
Comments