Skip to content
Snippets Groups Projects
Commit 7966caa5 authored by jo2-holdsworth's avatar jo2-holdsworth
Browse files

most of task 2 done + readme

parents
Branches
No related tags found
No related merge requests found
# Internet Of Things - Worksheet 2 part 1
![image](src/uwe.png)
**Module Name:** Internet Of Things
**Module Code:** UFCFVK‑15‑2
**Module Leader Name:** Benedict R. Gaster
- [Internet Of Things - Worksheet 2 part 1](#internet-of-things---worksheet-2-part-1)
- [Description](#description)
- [Getting Started](#getting-started)
- [Dependencies](#dependencies)
- [Installing](#installing)
- [Executing program](#executing-program)
- [Authors](#authors)
- [Version History](#version-history)
- [License](#license)
## Description
Morse code :: Worksheet(2 part 1)
A program to encode and decode morse.
* Task 1
* Task 2
## Getting Started
### Dependencies
*
### Installing
* pip install -r requirments.txt
### Executing program
```
python3 morse.py
```
## Authors
Contributors names and contact info
ex. Jack Holdsworth @ [my website](https://holdsworth.dev)
## Version History
* 0.2
* most of task 2 done
* README made
* 0.1
* init.
## License
This project is licensed under the GPL License - see the LICENSE.md file for details
morse.py 0 → 100644
class node:
def __init__(self, value, left=None, right=None):
self.value = value
self.leftChildNode = left
self.rightChildNode = right
def setLeftChildNode(self,nodes):
self.leftChildNode = nodes
def setRightChildNode(self,nodes):
self.rightChildNode = nodes
def hasLeftChildNode(self):
if self.leftChildNode != None:
return True
else:
return False
def hasRightChildNode(self):
if self.rightChildNode != None:
return True
else:
return False
def printNode(self, level=1,direction="S"):
for x in range(level):
print(" ", end = '')
print(direction + " " + str(self.value))
if self.hasLeftChildNode() == True:
self.leftChildNode.printNode((level+1),"L")
if self.hasRightChildNode() == True:
self.rightChildNode.printNode((level+1), "R")
def words(self,values):
if values:
x = values.split(" ")
decodes = []
for y in x:
print(self.value)
print("HELLO" + y)
decodes.append(self.decode(y))
# print(self.decode(y))
return decodes
def decode(self,values):
print(values)
if values:
if values[0] == ".":
return self.leftChildNode.decode(values[1:])
elif values[0] == "-":
return self.rightChildNode.decode(values[1:])
else:
print("ERROR")
else:
return self.value
def encode():
#dictionary ie e == --.-.-.-..-
x = x
alphabet = ["E","T","I","A","N","M","S","U","R","W","D","K","G","O","H","V","F","","L","","P","","J","B","X","C","Y","Z","Q","",""]
queue = []
start = node("start")
queue.append(start)
count = 0
while count < len(alphabet)-1:
# print(count)
parent = queue.pop(0)
# print(parent.value)
# print(alphabet[count])
childLeft = node(alphabet[count])
parent.setLeftChildNode(childLeft)
queue.append(childLeft)
count += 1
childRight = node(alphabet[count])
parent.setRightChildNode(childRight)
queue.append(childRight)
count += 1
start.printNode()
print(start.words("..- ..-"))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment