Kernel: Python 3 (system-wide)

COSC 130 - Homework 0

Kyle Anderson

Part 1: Arithmetic Operations

In this section of the assignment, we will demonstrate the following concepts:

  • Addition

  • Subtraction

  • Multiplication

  • Division

  • Exponentiation

In [1]:
print(7 + 2)
Out[1]:
9
In [2]:
print(7 - 2)
Out[2]:
5
In [3]:
print(7 * 2)
Out[3]:
14
In [4]:
print(7 / 2)
Out[4]:
3.5
In [5]:
print(7 ** 2)
Out[5]:
49

Part 2: Variables

In this section of the assignment, we will demonstrate the following concepts:

  • Creating variables

  • Printing the value of variables

  • Operations with variables

  • Nonlinear execution in notebooks

In [6]:
x = 91
In [7]:
x = 42
In [8]:
print(x)
Out[8]:
42
In [9]:
y = 7
In [10]:
print(y)
Out[10]:
7
In [11]:
print(x/y)
Out[11]:
6.0

Part 3: Comments

In this section of the assignment, we will demonstrate the following concepts:

  • Writing comments

  • Using comments to document code

  • Using comments to disable lines of code

In [12]:
# This is a comment print(2 + 5)
Out[12]:
7
In [13]:
# In this cell, we will calculte sales revenue. sales = 173 # Monththly widget sales price = 16.98 # Price per widget revenue = sales * price # Monthly revenue print(revenue)
Out[13]:
2937.54
In [14]:
print(12 / 6) # print(12 / 0) print(12 / 4)
Out[14]:
2.0 3.0

Part 4: Strings

In this section of the assignment, we will demonstate the following concepts:

  • Creating strings

  • Storing strings in variables

  • Printing multiple items

In [15]:
print("Hello, world!")
Out[15]:
Hello, world!
In [16]:
name = "Robbie Beane" print(name)
Out[16]:
Robbie Beane
In [17]:
print("Hello, my name is", name)
Out[17]:
Hello, my name is Robbie Beane
In [18]:
print("Hell, my name is ", name, ".", sep="")
Out[18]:
Hell, my name is Robbie Beane.