0% found this document useful (0 votes)
2 views

1.1 Variables Assignment, Math Ops and Data Types

The document provides an introductory lecture on Python, explaining how to define variables and their data types, including strings, floats, integers, and booleans. It also illustrates basic mathematical operations and includes a practice opportunity involving investment calculations. The document emphasizes Python's advantages over Excel in terms of scalability, efficiency, and automation capabilities.

Uploaded by

123 45
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

1.1 Variables Assignment, Math Ops and Data Types

The document provides an introductory lecture on Python, explaining how to define variables and their data types, including strings, floats, integers, and booleans. It also illustrates basic mathematical operations and includes a practice opportunity involving investment calculations. The document emphasizes Python's advantages over Excel in terms of scalability, efficiency, and automation capabilities.

Uploaded by

123 45
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

# Let's define a variable named "company_name" and assign a value to it

# 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'

# Let's display the content of "company_name"


company_name

'Apple'

# Let's confirm the datatype for our variable


# Note that the output is "str" which stands for string
type(company_name)

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

# Let's confirm the datatype for our variable


# Note that the datatype is "float" which stands for floating points
# Floating points are real numbers with a decimal point dividing the integer and fractional parts
type(revenue)

float

# Let's define and display the third entry in the table and assign an integer to it
num_employees = 154000
num_employees

154000

# Let's confirm the datatype for our variable


# Note that the output is "int" which stands for integer
# Integers are whole numbers (no decimals) that could be positive or negative
type(num_employees)

int

# Let's define and display the last element in the table


pays_dividend = True
pays_dividend

True

# "bool" stands for Boolean which is a datatype that has one of two possible values: True or False
type(pays_dividend)

bool

# After we define variables, we can then perform math operations on them


# Math operations can be easily performed in Python
# Addition (+), Subtraction (-), Multiplication (*), Division (/)

# Let's assume that the number of employees increased by 100


# Note that we overwrite the previous value of "num_employees" with the new value
num_employees = num_employees + 100
num_employees

154100

# Let's assume that the number of employees has now doubled


# We will learn how to store tablular data efficiently later in the course using Pandas library
num_employees = num_employees * 2
num_employees

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

PRACTICE OPPORTUNITY SOLUTION


PRACTICE OPPORTUNITY SOLUTION:

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

# Define the account balance


balance = 5000
balance

# Confirm the datatype which is integer


type(balance)

# Define the price per share


price = 142.5
price

# Confirm the datatype which is float


type(price)

# 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

You might also like