🚀
Python Crash Course
02 Python Crash Course Exercises
++++
Data Science
May 2026×Notebook lesson

Notebook converted from Jupyter for blog publishing.

02-Python Crash Course Exercises

Driptanil Datta
Driptanil DattaSoftware Developer

Exercises

Answer the questions or complete the tasks outlined in bold below, use the specific method described if applicable.

** What is 7 to the power of 4?**

7 ** 4
RESULT
2401

** Split this string:**

s = "Hi there Sam!"

**into a list. **

s = "Hi there Same!"
s.split(" ")
RESULT
['Hi', 'there', 'Same!']

** Given the variables:**

planet = "Earth" diameter = 12742

** Use .format() to print the following string: **

The diameter of Earth is 12742 kilometers.

planet = "Earth"
diameter = 12742
f"The diameter of {planet} is {diameter} kilometers."
RESULT
'The diameter of Earth is 12742 kilometers.'

** Given this nested list, use indexing to grab the word "hello" **

lst = [1,2,[3,4],[5,[100,200,['hello']],23,11],1,7]
lst[3][1][2][0]
RESULT
'hello'

** Given this nested dictionary grab the word "hello". Be prepared, this will be annoying/tricky **

d = {'k1':[1,2,3,{'tricky':['oh','man','inception',{'target':[1,2,3,'hello']}]}]}

** What is the main difference between a tuple and a list? **

# Tuple is immutable

** Create a function that grabs the email website domain from a string in the form: **

user@domain.com

So for example, passing "user@domain.com" would return: domain.com

domainGet('user@domain.com')
RESULT
'domain.com'

** Create a basic function that returns True if the word 'dog' is contained in the input string. Don't worry about edge cases like a punctuation being attached to the word dog, but do account for capitalization. **

findDog('Is there a dog here?')
RESULT
True

** Create a function that counts the number of times the word "dog" occurs in a string. Again ignore edge cases. **

countDog('This dog runs faster than the other dog dude!')
RESULT
2

** Use lambda expressions and the filter() function to filter out words from a list that don't start with the letter 's'. For example:**

seq = ['soup','dog','salad','cat','great']

should be filtered down to:

['soup','salad']

seq = ['soup','dog','salad','cat','great']

Final Problem

**You are driving a little too fast, and a police officer stops you. Write a function to return one of 3 possible results: "No ticket", "Small ticket", or "Big Ticket". If your speed is 60 or less, the result is "No Ticket". If speed is between 61 and 80 inclusive, the result is "Small Ticket". If speed is 81 or more, the result is "Big Ticket". Unless it is your birthday (encoded as a boolean value in the parameters of the function) -- on your birthday, your speed can be 5 higher in all cases. **

def caught_speeding(speed, is_birthday):
    pass
caught_speeding(81,True)
RESULT
'Small Ticket'
caught_speeding(81,False)
RESULT
'Big Ticket'

Great job!

Drip

Driptanil Datta

Software Developer

Building full-stack systems, one commit at a time. This blog is a centralized learning archive for developers.

Legal Notes
Disclaimer

The content provided on this blog is for educational and informational purposes only. While I strive for accuracy, all information is provided "as is" without any warranties of completeness, reliability, or accuracy. Any action you take upon the information found on this website is strictly at your own risk.

Copyright & IP

Certain technical content, interview questions, and datasets are curated from external educational sources to provide a centralized learning resource. Respect for original authorship is maintained; no copyright infringement is intended. All trademarks, logos, and brand names are the property of their respective owners.

System Operational

© 2026 Driptanil Datta. All rights reserved.