Develop your first Python Project
December 9, 2025
1 TASK #1: UNDERSTAND VARIABLES ASSIGNMENT
[6]: # Define a variable named "x" and assign a number (integer) to it
# integer is a whole number (no decimals) that could be positive or negative
x=250
[8]: # Let's view "x"
x
[8]: 250
[13]: # Define a variable named "y" and assign a number (float) to it
# Float are real numbers with a decimal point dividing the integer and␣
↪fractional parts
y=500.5
[14]: # Let's view "y"
y
[14]: 500.5
[16]: # Let's overwrite "y" (assume your portfolio value increased)
y=300.5
[17]: # Notice that "y" will only contain the most recent value
y
[17]: 300.5
[18]: # Get the type of "x" which is integer
# integer is a whole number (no decimals) that could be positive or negative
type(x)
[18]: int
1
[19]: # Get the type of "y" which is float
# Float are real numbers with a decimal point dividing the integer and␣
↪fractional parts
type(y)
[19]: float
MINI CHALLENGE #1: - We defined a variable x and we assigned these 4 values listed below to
it. Without executing any code cells, what will these lines of code generate? - Verify your answer
by executing the code cells
z = 1000
z = 2000
z = 5000
z = 6000
z
[20]: z=1000
z=2000
z=5000
z=6000
z
[20]: 6000
2 TASK #2: PERFORM MATH OPERATIONS IN PYTHON
[23]: # Define a variable named i and initialize it with 20
# Let's assume that we want to increment the value by 4
i = 20
i = i + 4
i
[23]: 24
[25]: # Let's assume that you own a little grocery store
# The price of 1 bottle of milk is $3 and we currently have 50 bottles
# We can calculate the total dollar value of our inventory as follows:
count = 50
price = 3
inventory = count * price
inventory
[25]: 150
[28]: # Let's assume you have $550 USD in our bank account
# We want to buy x number of IBM stocks using the total amount
2
# each IBM stock is priced at $128 each
account_balance = 550
IBM_price = 128
[29]: # Divide the account balance by Amazon stock price and place the answer in units
unts = account_balance/IBM_price
units
[29]: 4.296875
MINI CHALLENGE #2: - Write a code that takes in APPLE (AAPL) stock prices at two days
and calculate the return: - AAPL price on day 1 = $135 - AAPL price on day 2 = $150
[32]: AAPL_price_1 = 135
AAPL_price_2 = 150
prce_diff = AAPL_price_2 - AAPL_price_1
percentage_change = prce_diff / AAPL_price_1 * 100
percentage_change
[32]: 11.11111111111111
3 TASK #3: UNDERSTAND PRINT AND INPUT OPERA-
TIONS
[33]: # Print function is used to print elements on the screen
# Define a string x
# A string in Python is a sequence of characters
# String in python are surrounded by single or double quotation marks
x = "Welcome to Python's guided project in python"
[34]: print(x)
Welcome to Python's guided project in python
[35]: # Obtain the data type for 'x'
type(x)
[35]: str
[40]: # The format() method formats the specified value and insert it in the␣
↪placeholder
# The placeholder is defined using curly braces: {}
company_name = 'Amazon'
shares = 400
3
print("I own {} shares of {} ".format(shares,company_name))
I own 400 shares of Amazon
[41]: # input is a built-in function in python
# Obtain client data such as name, country and e-mail and print them all out on␣
↪the screen
name = input('Welcome to the store, please enter your name:')
country = input('Enter your country: ')
email = input('Enter your e-mail: ')
Welcome to the store, please enter your name:Rania
Enter your country: Morocco
Enter your e-mail: [Link]@[Link]
[42]: name
[42]: 'Rania'
[43]: country
[43]: 'Morocco'
[44]: email
[44]: '[Link]@[Link]'
[45]: print("My name is {}, I live in {}, and my email is {}".
↪format(name,country,email))
My name is Rania, I live in Morocco, and my email is [Link]@[Link]
MINI CHALLENGE #3: - Write a code that takes in the name of the stock, price at which it is
selling, the number of stocks that you want to own and prints out the total funds required to buy
this stock. Find a sample expected output below: - Enter the price of the stock you want to buy:
3000
- Enter the number of stocks that you want to buy: 5 - Enter the name of the stock that you want
to buy: AMZN - The total funds required to buy 5 number of AMZN stocks at 3000 is: 15000
[46]: x = input('Enter the price of the stock you want to buy :')
x = int(x)
y = input('Enter the number of stocks you want to buy :')
y = int(y)
z = input("Enter the name of the stock you want to buy :")
print('The total funds required to buy {} number of {} stocks at {} is {}.
↪format(y,z,x,x*y)')
4
Enter the price of the stock you want to buy :30
Enter the number of stocks you want to buy :100
Enter the name of the stock you want to buy :AAPL
The total funds required to buy {} number of {} stocks at {} is
{}.format(y,z,x,x*y)
4 TASK #4: UNDERSTAND LISTS DATA TYPES
[47]: # A list is a collection which is ordered and changeable.
# List allows duplicate members.
grocery_list = ['oranges','apples','bananas']
grocery_list
[47]: ['oranges', 'apples', 'bananas']
[48]: # Obtain the datatype
type(grocery_list)
[48]: list
[49]: # Access specific elements in the list with Indexing
# Note that the first element in the list has an index of 0 (little confusing␣
↪but you'll get used to it!)
grocery_list[2]
[49]: 'bananas'
MINI CHALLENGE #4: - Print the first, second and last element in the list below
grocery_list = ['milk', 'rice', 'eggs', 'bread', 'oranges', 'water']
[50]: grocery_list = ['milk', 'rice', 'eggs', 'bread', 'oranges', 'water']
grocery_list[0]
[50]: 'milk'
[51]: grocery_list[1]
[51]: 'rice'
[52]: grocery_list[5]
[52]: 'water'
5
5 TASK #5: UNDERSTAND COMPARISON OPERATORS
AND CONDITIONAL STATEMENTS
[53]: # Comparison Operator output could be "True" or "False"
# Let's cover equal '==' comparison operator first
# It's simply a question: "Is x equals y or not?"
# "True" output means condition is satisfied
# "False" output means Condition is not satisfied (condition is not true)
x = 500
y = 500
x == y
[53]: True
[54]: # Greater than or equal operator '>='
x = 20
y =40
x >=y
[54]: False
[58]: # Note that '==' is a comparison operator
# Note that '=' is used for variable assignment (put 10 in x)
x = 10
[59]: x
[59]: 10
• A simple if-else statement is written in Python as follows:
if condition:
statement #1
else:
statement #2
• If the condition is true, execute the first indented statement
• if the condition is not true, then execute the else indented statements.
• Note that Python uses indentation (whitespace) to indicate code sections and scope.
[62]: # Let's take an input from the user and grant or deny access accordingly
name = input('Enter your username: ')
if name == 'rania':
print('Access granted')
else:
print('Access denied')
6
Enter your username: rania
Access granted
[64]: x = int(input('Please enter an integer from 1 to 1000:'))
if x % 2 == 0:
print('Number is even')
else:
print('Number is odd')
Please enter an integer from 1 to 1000:5
Number is odd
MINI CHALLENGE #5: - Write a code that takes a number from the user and indicates if it’s
positive or negative
[65]: x = int(input('Enter an integer'))
if x < 0:
print('Number is negative')
elif x > 0:
print('Number is positive')
else:
print('Number is zero')
Enter an integer0
Number is zero
6 TASK #6: DEVELOP FUNCTIONS IN PYTHON
[66]: # Define a function that takes in two argument x and y and returns their␣
↪multiplication
def multiplication(x,y):
return x * y
[67]: # Call the function
multiplication(5,6)
[67]: 30
MINI CHALLENGE #6: - Write a code that takes in three inputs from the user and calculate
their sum
[71]: def summation(x,y,z):
return x + y + z
[72]: num1 = int(input('Enter the first number :'))
num2 = int(input('Enter the second number :'))
num3 = int(input('Enter the third number'))
7
Enter the first number :10
Enter the second number :20
Enter the third number30
[73]: summation(num1,num2,num3)
[73]: 60
7 TASK #7: UNDERSTAND FOR AND WHILE LOOPS
[74]: # List of strings
grocery_list = ['milk', 'rice', 'eggs', 'bread', 'oranges', 'water']
grocery_list
[74]: ['milk', 'rice', 'eggs', 'bread', 'oranges', 'water']
[76]: for i in grocery_list:
print(i)
print('Hello world')
milk
Hello world
rice
Hello world
eggs
Hello world
bread
Hello world
oranges
Hello world
water
Hello world
[77]: # Range() generates a list of numbers, which is used to iterate over with for␣
↪loops.
# range() is 0-index based, meaning list indexes start at 0, not 1.
# The last integer generated by range() is up to, but not including, last␣
↪element.
# Example: range(0, 7) generates integers from 0 up to, but not including, 7.
for i in range(7):
print(i)
0
1
2
3
4
8
5
6
[78]: # While loop can be used to execute a set of statements as long as a certain␣
↪condition holds true.
i = 0
while i <= 10:
print(i)
i = i+1
0
1
2
3
4
5
6
7
8
9
10
MINI CHALLENGE #7: - Write a code that displays numbers from 1 to 10 using for and while
loops
[80]: for i in range(1,11):
print(i)
1
2
3
4
5
6
7
8
9
10
8 TASK #8: CAPSTONE PROJECT
Develop a guessing game that performs the following: - The system will automatically generate
a random number between 1 and 100. - Users can insert any number between 1 and 100 - The
program shall be able to compare the number generated by the system and the number that has
been entered by the user. The program shall print out one of the following options to help the user
improve their next guess: - You are right, great job! - Your guess is low, try again! - your guess is
high, try again!
• The program exits when the user guess matches the number generated by the system
9
[ ]: import random
true_number = [Link](1,100)
true_number
[84]: guess_number = int(input('Ennter your guess between 1 and 100 :'))
guess_number
Ennter your guess between 1 and 100 :50
[84]: 50
[ ]: while True:
if guess_number == true_number:
print('YOU ARE RIGHT ,GOOD JOB')
break
elif guess_number < true_number:
print('YOUR GUESS IS LOW, PLEASE TRY AGAIN')
guess_number = int(input('Enter your guess between 1 and 100 :'))
elif guess_number > true_number:
print('YOUR GUESS IS HIGH, PLEASE TRY AGAIN')
guess_number = int(input('Enter your guess between 1 and 100 :'))
9 EXCELLENT JOB
10 MINI CHALLENGES SOLUTIONS
MINI CHALLENGE #1 SOLUTION: - We defined a variable x and we assigned these 4 values
listed below to it. Without executing any code cells, what will these lines of code generate? - Verify
your answer by executing the code cells
z = 1000
z = 2000
z = 5000
z = 6000
z
[ ]: # The output of this code is 5000
# Initially we put 1000 in z, then we overwrite it by placing 2000 in z, and␣
↪then 5000 in z & finally 6000 in z
z = 1000
z = 2000
z = 5000
z = 6000
z
MINI CHALLENGE #2 SOLUTION: - Write a code that takes in APPLE (AAPL) stock prices at
two days and calculate the return: - AAPL price on day 1 = $135 - AAPL price on day 2 = $150
10
[ ]: AAPL_price_1 = 135
AAPL_price_2 = 150
price_diff = AAPL_price_2 - AAPL_price_1
percentage_change = price_diff / AAPL_price_1 * 100
percentage_change
MINI CHALLENGE #3 SOLUTION: - Write a code that takes in the name of the stock, price
at which it is selling, the number of stocks that you want to own and prints out the total funds
required to buy this stock. Find a sample expected output below: - Enter the price of the stock
you want to buy: 3000
- Enter the number of stocks that you want to buy: 5 - Enter the name of the stock that you want
to buy: AMZN - The total funds required to buy 5 number of AMZN stocks at 3000 is: 15000
[ ]: x = input("Enter the price of the stock you want to buy: ")
x = int(x)
y = input("Enter the number of stocks that you want to buy: ")
y = int(y)
z = input("Enter the name of the stock that you want to buy: ")
print('The total funds required to buy {} number of {} stocks at {} is {}'.
↪format(y,z,x, x*y))
MINI CHALLENGE #4 SOLUTION: - Print the first, second and last element in the list below
grocery_list = ['milk', 'rice', 'eggs', 'bread', 'oranges', 'water']
[ ]: grocery_list = ['milk', 'rice', 'eggs', 'bread', 'oranges', 'water']
print(grocery_list[0])
print(grocery_list[1])
print(grocery_list[-1])
MINI CHALLENGE #5 SOLUTION: - Write a code that takes a number from the user and
indicates if it’s positive or negative
[ ]: x = int(input("Please enter an integer: "))
if x < 0:
print('Number is Negative')
elif x > 0:
print('Number is Positive')
else:
print ('Number is zero')
MINI CHALLENGE #6 SOLUTION: - Write a code that takes in three inputs from the user and
calculate their sum
[ ]: def summation(x, y, z):
return x + y + z
11
[ ]: num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
num3 = int(input("Enter the third number: "))
total = summation(num1, num2, num3)
print('Total balance = {}'.format(total))
MINI CHALLENGE #7 SOLUTION: - Write a code that displays numbers from 1 to 10 using for
and while loops
[ ]: i = 1
while (i < 11):
print (i)
i = i+1
[ ]: for i in range(1, 11):
print(i)
[ ]:
12