This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i = 5 | |
print(i) | |
i = i+1 | |
print(i) | |
s = '''This is a multi-line string. | |
This is the second line.''' | |
print(s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def user_input_until_exit(): | |
user_input = input() | |
while user_input != 'exit': | |
user_input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |