commit 054879c11dbf0730332e025f6b07cd85ac73dd5e Author: gabe venberg Date: Mon Feb 8 11:29:13 2021 -0600 inital commit. about to start file IO. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f58d730 --- /dev/null +++ b/.gitignore @@ -0,0 +1,139 @@ +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +doc/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +pythonenv* + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# profiling data +.prof diff --git a/collatz/collatz.py b/collatz/collatz.py new file mode 100755 index 0000000..073528a --- /dev/null +++ b/collatz/collatz.py @@ -0,0 +1,16 @@ + +def nextInSequence(number): + if isinstance(number, int): + if number % 2 == 0: + return number // 2 + else: + return 3*number+1 + else: + raise TypeError('input must be int!') + +def seqenceLength(number): + length = 0 + while number != 1: + number = nextInSequence(number) + length += 1 + return length diff --git a/collatz/collatzSearch.py b/collatz/collatzSearch.py new file mode 100755 index 0000000..0a0c9b0 --- /dev/null +++ b/collatz/collatzSearch.py @@ -0,0 +1,24 @@ +#! /usr/bin/env python3 + +import sys +import collatz + +usage='usage: collatzSearch [digits] outputs the lenght of the collatz sequence for every number less than 10^digits' + +if len(sys.argv)<2: + print(usage) + sys.exit() +digits = sys.argv[1] + +try: + digits = int(digits) +except: + print(usage) + sys.exit() + +nextNumber = 1 +maxNumber = 10**digits + +while nextNumber secretNumber: + print('your guess is too high.') + else: + break +if guess == secretNumber: + print('you guessed correctly! it only took you '+str(guessesTaken)+' guesses!') +else: + print('you were not able to guess in 10 guesses. the number I was thinking of was '+str(secretNumber)) diff --git a/password.py b/password.py new file mode 100755 index 0000000..c28a6a6 --- /dev/null +++ b/password.py @@ -0,0 +1,9 @@ +#! /usr/bin/env python3 +name = 'mary' +password = 'swordfish' +if name == 'mary': + print('hello mary') + if password == 'swordfish': + print('acess granted') + else: + print('Wrong Password') diff --git a/pigLatin.py b/pigLatin.py new file mode 100755 index 0000000..8dd2dd2 --- /dev/null +++ b/pigLatin.py @@ -0,0 +1,61 @@ +#! /usr/bin/env python3 +import sys + +if len(sys.argv)<2: + print('usage: piglatin [text] -translate text to piglatin') + sys.exit() + +message = sys.argv[1] +def translateToPigLatin(message): + vowels=('a', 'e', 'i', 'o', 'u', 'y') + + piglatin=[] #list of the words + for word in message.split(): + #seperate the non-letters at the start of the word + prefixNonLetters = '' + while len(word) > 0 and not word[0].isalpha(): + prefixNonLetters += word[0] + word = word[1:] + + if len (word) == 0: + piglatin.append(prefixNonLetters) + continue + + suffixNonLetters = '' + while len(word)>0 and not word[-1].isalpha(): + suffixNonLetters = word[-1]+suffixNonLetters + word = word[:-1] + + #remember if word was in uppercase or title case. + wasUpper = word.isupper() + wasTitle = word.istitle() + + #make word lowercase for translation. + word = word.lower() + + #seperate the consanants at the end of the word. + prefixConsonants = '' + while len(word) > 0 and not word[0] in vowels: + prefixConsonants += word[0] + word = word[1:] + + #add pig latin ending + + if prefixConsonants == '': + word += 'yay' + else: + word += prefixConsonants+'ay' + + #set the word back to upercase or titlecase. + if wasUpper: + word=word.upper() + if wasTitle: + word = word.title() + + #add non letters back. + piglatin.append(prefixNonLetters + word + suffixNonLetters) + + #join all the words back into a string. + return' '.join(piglatin) +print(translateToPigLatin(message) + diff --git a/rock_paper_scissors.py b/rock_paper_scissors.py new file mode 100755 index 0000000..22948ed --- /dev/null +++ b/rock_paper_scissors.py @@ -0,0 +1,68 @@ +#! /usr/bin/env python3 + +import random, sys + +print('ROCK, PAPER, SCISSORS') + +#variables to keep track of wins, losses, ties. +wins =0 +losses = 0 +ties = 0 + +while True: #main game loop. + print('%s Wins, %s Losses, %s Ties' %(wins, losses, ties)) + while True: #input loop + print('Enter your move: (r)ock, (p)aper, (s)cissors, or (q)uit') + playerMove = input() + if playerMove == 'q': + sys.exit() #exit program + elif playerMove == 'r' or playerMove == 'p' or playerMove == 's': + break #get out of input loop. + else: + print('type of of r, p, s, or q.') + + #display player choice. + if playerMove == 'r': + print('ROCK vs ...') + elif playerMove == 'p': + print('PAPER vs ...') + elif playerMove == 's': + print('SCISSORS vs ...') + + #determine computer move and display it. + randomNumber = random.randint(1,3) + if randomNumber == 1: + computerMove = 'r' + print('ROCK') + if randomNumber == 2: + computerMove = 'p' + print('PAPER') + if randomNumber == 3: + computerMove = 's' + print('SCISSORS') + + #determine and display results. + if playerMove == computerMove: + print('Its a Tie!') + ties += 1 + elif playerMove == 'r': + if computerMove == 's': + print('You Win!') + wins += 1 + else: + print('You Loose!') + losses += 1 + elif playerMove == 'p': + if computerMove == 'r': + print('You Win!') + wins +=1 + else: + print('You Loose!') + losses += 1 + elif playerMove == 's': + if computerMove == 'p': + print('You Win!') + wins +=1 + else: + print('You Loose!') + losses +=1 diff --git a/spam.py b/spam.py new file mode 100755 index 0000000..c7fe2c1 --- /dev/null +++ b/spam.py @@ -0,0 +1,5 @@ +#! /usr/bin/env python3 +spam = 0 +while spam <5: + print('spam'+str(spam)) + spam = spam+1 diff --git a/strongPassword.py b/strongPassword.py new file mode 100755 index 0000000..04ad010 --- /dev/null +++ b/strongPassword.py @@ -0,0 +1,29 @@ +#! /usr/bin/env python3 + +import re, sys + +if len(sys.argv)<2: + print('usage: strongPassword [password] tests whether the password is at least 8 characters, contains both upper and lowercase, and has at least one digit/symbol, OR consists of at least 3 words of 4 letters each, containing both upper and lower case.') + sys.exit() + +def checkShortPassword(password): + if len(password)<8: + return false + hasLower = re.search('[a-z]', password) + hasCaps = re.search('[A-Z]', password) + hasDigitOrSymbol = re.search('[\d]|[\W_\s]', password) + # + return hasLower and hasCaps and hasDigitOrSymbol + +def checkLongPassword(password): + has3Words = re.match('\s*\S+(?:\s+\S+){3,}', password) + hasLower = re.search('[a-z]', password) + hasCaps = re.search('[A-Z]', password) + return has3Words and hasLower and hasCaps + +password = sys.argv[1] + +if checkLongPassword(password) or checkShortPassword(password): + print('password is strong') +else: + print('password is weak!') diff --git a/tmp.py b/tmp.py new file mode 100755 index 0000000..05a7e62 --- /dev/null +++ b/tmp.py @@ -0,0 +1,3 @@ +#! /usr/bin/env python3 + + diff --git a/your_name.py b/your_name.py new file mode 100755 index 0000000..63a8560 --- /dev/null +++ b/your_name.py @@ -0,0 +1,6 @@ +#! /usr/bin/env python3 +name ='' +while name != 'your name': + print('please type your name') + name = input() +print('thank you!') diff --git a/zigzag.py b/zigzag.py new file mode 100755 index 0000000..64953f7 --- /dev/null +++ b/zigzag.py @@ -0,0 +1,20 @@ +#! /usr/bin/env python3 + +import time, sys + +maxIndent = 100 #how many spaces the zigzag should move +linewidth = 5 #width of line +linechar = '*' +indent = 0 +indentIncreasing = 1 + +try: + while True: + print((' '*indent)+(linechar*linewidth)) #form the string for the current line + indent += indentIncreasing + if indent > maxIndent or indent <= 0: + indentIncreasing *= -1 # change direction + time.sleep(0.01) + +except KeyboardInterrupt: + sys.exit()