1.1 Variables Assignment, Math Ops and Data Types
1.1 Variables Assignment, Math Ops and Data Types
# A string in Python is a sequence of characters that are surrounded by single or double quotations
# You can run the cell by clicking "shift + enter" or by clicking the "Run" button
# Note that you might be wondering - I can do this in Excel, why am I using Python for this?!
# This is an introductory lecture to Python, we will build on what we learn to develop powerful applications
# Python offers greater scalability and efficiency compared to Excel
# It offers faster execution and allows for automating complex tasks
# It also comes with several open-source libraries so we do not have to develop code from scratch
company_name = 'Apple'
'Apple'
str
# Let's define and display the second entry in the table and assign a decimal number to it
revenue = 394.32
revenue
394.32
float
# Let's define and display the third entry in the table and assign an integer to it
num_employees = 154000
num_employees
154000
int
True
# "bool" stands for Boolean which is a datatype that has one of two possible values: True or False
type(pays_dividend)
bool
154100
308200
PRACTICE OPPORTUNITY:
Assume that you have $5000 in your brokerage account and you decided to invest the entire amount in Procter & Gamble
(P&G) stock which is trading at \$142.5 per share. Complete the following tasks:
1. Write a Python code that defines two variables for the account balance and P&G stock price. Feel free to select any
valid variable names
2. Confirm variables datatypes
3. Calculate number of shares that you can buy with the available balance in your account
balance = 5000
balance
5000
type(balance)
int
price = 142.5
price
142.5
type(price)
float
num_shares = balance/price
num_shares
35.08771929824562
round(num_shares)
35
Assume that you have $5000 in your brokerage account and you decided to invest the entire amount in Procter & Gamble
(P&G) stock which is trading at \$142.5 per share. Complete the following tasks:
1. Write a Python code that defines two variables for the account balance and P&G stock price. Feel free to select any
valid variable names
2. Confirm variables datatypes
3. Calculate number of shares that you can buy with the available balance in your account
# Calculate the number of shares by dividing the brokerage balance by P&G stock price
# Place the answer in num_shares
num_shares = balance/price
num_shares
# Note that you can round your answer to the nearest integer by using the round function
round(num_shares)
EXCELLENT JOB
y = False
type(y)
bool
Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js