Skip to content

Instantly share code, notes, and snippets.

View shamikalashawn's full-sized avatar
💭
Polishing my latest app!

Shamika La Shawn shamikalashawn

💭
Polishing my latest app!
View GitHub Profile
@shamikalashawn
shamikalashawn / Guess The Number Game
Last active February 7, 2017 20:29
Guess a number between 0 and 100. You'll get clues as to whether your guess is "higher" or "lower" than the actual answer.
from random import randint
print ('---------------------------------------------' + '\n' + ' GUESS THE NUMBER APP' + '\n' + '---------------------------------------------' + '\n')
number = randint(1, 100)
while True:
guess = input('Guess a number between 0 and 100 ("quit" to stop): ')
if not guess.isdigit():
@shamikalashawn
shamikalashawn / Variable Size Box
Created February 6, 2017 23:37
Make a box of any size with any character you want. Can't decide? No worries, there is a default box size of 4 using the "*" character.
def variable_size_box(size = 4, character = '*'):
box = ''
for col in range(size):
if col == 0:
box = box
else:
box = box + '\n'
for row in range(size):
box = box + character
box = box + '\n'
@shamikalashawn
shamikalashawn / Var
Created February 6, 2017 23:36
An introductory use of variables and multiline strings.
i = 5
print(i)
i = i+1
print(i)
s = '''This is a multi-line string.
This is the second line.'''
print(s)
@shamikalashawn
shamikalashawn / User Input
Created February 6, 2017 23:35
Got something to say? Say away! This function takes user input until you type "exit".
def user_input_until_exit():
user_input = input()
while user_input != 'exit':
user_input
@shamikalashawn
shamikalashawn / Triple Nested Loop
Created February 6, 2017 23:34
Using triple nested loops, a number pyramid is returned with periods and numbers printed on each line. The number of periods is determined by what line it is on. Line # - size = number of periods.
def triple_nested_loop(size):
charlist = []
numlist = []
answer = ''
sizelist = range(1,size)
for dot in reversed(sizelist):
charlist.append('.' * dot)
for num in range(1,size+1):
numlist.append(str(num) * num + '\n')
for elem in range(len(numlist)):
@shamikalashawn
shamikalashawn / String Dictionary
Created February 6, 2017 23:28
A string is collected then each element of the string is turned into a value in a dictionary while its key is its index.
string = input('Please type in a string.')
if type(string) != str:
string = input('That is not a string! Please type a string.')
else:
strindex = range(len(string))
strlist = []
for letter in string:
strlist.append(letter)
stringdict = dict(zip(strindex, strlist))
@shamikalashawn
shamikalashawn / String Format
Created February 6, 2017 23:25
A short program that utilizes string formatting to make a few silly sentences.
age = 31
name = 'Shamika'
print('{0} was {1} years old when he wrote this book'.format(name, age))
print('Why is {0} playing with that python?'.format(name))
@shamikalashawn
shamikalashawn / Simple Calculator
Created February 6, 2017 23:23
Add, subtract, multiply, and divide two numbers.
while True:
print("Options:")
print("Enter 'add' to add two numbers")
print("Enter 'subtract' to subtract two numbers")
print("Enter 'multiply' to multiply two numbers")
print("Enter 'divide' to divide two numbers")
print("Enter 'quit' to end the program")
user_input = input(":")
if user_input == "quit":
break
@shamikalashawn
shamikalashawn / Powers of Two
Created February 6, 2017 23:21
The number entered is the exponent for the power of 2.
def powers_of_two(power):
num = 1
if power == 0:
return 1
elif power > 0:
for x in range(1,power+1):
num *= 2
return num
@shamikalashawn
shamikalashawn / Pyg Latin
Created February 6, 2017 23:20
Your word is turned into a "Pyg Latin" version of the word with the first letter going to the end and "ay" being added.
pyg = 'ay'
while True:
original = input('Enter a word to pygafy (Press Enter to quit): ')
if original == '':
print ("It's your perogative to quit. No judgement here.")
break
elif len(original) > 0 and original.isalpha(): #test if string entered is empty and all leters
word = original.lower() #stores lowercase version of input
first = word[0] #first letter in the string
new_word = word + first + pyg