Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
49 changes: 39 additions & 10 deletions Demos/Module2/variables_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,52 @@
# Demo file for variables
#

# Declare a variable and initialize it
# # Declare a variable and initialize it
# person_name = 'John Smith'
# person_address = '101 Main Street'
# print(f'{person_name} lives at {person_address}')

# Inspect the data type
# # Inspect the data type
# print(type(person_name))

# re-declaring the variable works
# # re-declaring the variable works
# person_name = 1
# print(person_name)
# print(type(person_name))
# print(f'{person_name} lives at {person_address}')
# print(str(person_name) + " lives at " + person_address)

# # String literals
# print('John says: "How are you?"')
# print('''John says: "That is Jenny's car".''')

# ERROR: variables of different types cannot be combined
#print("this is a string" + 123)
# # delete definition of variable previously declared
# del(person_name)
# print(person_name)

# But this works: variables of different types cannot be combined
# # data type casting
# item_price = '12.10'
# stock_price = 12.15

# result = 25 / 5
# type(result)
# print(result)

# Global vs. local variables in functions
# print(item_price * 2)

# delete definition of variable previously declared
# type(item_price)
# type(stock_price)

# data type casting
# greeting = 'Hello world'
# print(greeting.upper())
# print(greeting.isnumeric())
# print(len(greeting))

# comparing float numbers
full_name = input('Please enter Name:')

print(f'You entered: {full_name}')

age = input('Please enter age:')
print(type(int(age)))

print(f'{full_name} is {age} years old')
30 changes: 30 additions & 0 deletions Demos/Module3/conditionals_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,40 @@ def main():
x, y = 10, 100

# conditional flow uses if, elif, else
if( x < y):
st = 'x is less than y'
elif(x > y):
st = 'x is greater than y'
else:
st = 'x is the same as y'

print(st)

# conditional statements let you use "a if C else b"
st = 'x is less than y' if (x < y) else "x is greater or the same as y"

print(st)

# conditional logic with IN operator
city = "Raleigh"
if city in ('Raleigh', 'Charlotte', 'Asheville'):
print('You live in North Carolina')
else:
print('You live somewhere else.')

if 1.1 + 2.2 == 3.3:
print('1.1 + 2.2 == 3.3')
else:
print('1.1 + 2.2 != 3.3')

tolerance = 0.00001

if abs((1.1 + 2.2) - 3.3) < tolerance:
print('1.1 + 2.2 == 3.3')
else:
print('1.1 + 2.2 != 3.3')



if __name__ == "__main__":
main()
15 changes: 14 additions & 1 deletion Demos/Module3/error_handling_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@


x = 42
y = 0
y = '2'

# Division
try:
result = x / y
except ZeroDivisionError:
result = 0
print('y cannot be zero')
except TypeError as e:
result = float(x) / float(y)
print('Automatically casted string to float')
except:
result = '0'
print('Something went wrong!')
finally:
print(f'Result: {result}')
21 changes: 15 additions & 6 deletions Demos/Module3/functions_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@
# Example file for working with functions
#

# define a basic function
# name = "John Doe"

# function with arguments
# # define a basic function
# def some_function():
# global name
# name = 'James Smith'
# return f'Hello, {name}'

# function with return value
# greeting = some_function()

# function with default value for an argument
# print(name)
# print(greeting)

#function with variable number of arguments

# Lambda functions
# Lambda functions
def addition(arg1, arg2):
return arg1 + arg2

print(addition)
print((lambda arg1, arg2: arg1 + arg2))
10 changes: 10 additions & 0 deletions Labs/Lab02/simple_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Lab 2
#

# calculate the circumference of a circle

radius = float(input("Please enter radius:"))
pi = 3.1416
circumference = 2 * pi * radius
print(f'The circumference is:{circumference}')
36 changes: 36 additions & 0 deletions Labs/Lab03/simple_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
def add(x, y):
return x + y
def sub(x, y):
return x - y
def mul(x, y):
return x * y
def div(x, y):
try:
result = x / y
except ZeroDivisionError:
result = 0
print("Cannot divide by zero.")
finally:
return result


operation = input("Please enter operation:")
first_number = input("Please enter first number:")
second_number = input("Please enter second number:")

first_number = float(first_number)
second_number = float(second_number)

if operation.upper() == 'ADD':
result = add(first_number, second_number)
elif operation.upper() == 'SUB':
result = sub(first_number, second_number)
elif operation.upper() == 'MUL':
result = mul(first_number, second_number)
elif operation.upper() == 'DIV':
result = div(first_number, second_number)
else:
result = 0
print(f'Unknown Operation: {operation}')

print(f"Result: {result}")