Skip to content

Instantly share code, notes, and snippets.

View calthoff's full-sized avatar

Cory Althoff calthoff

View GitHub Profile
for i in range(n):
i += 1
i -= 1
print(i)
for i in range(n):
for j in range(n):
print(i + j)
for i in range(n):
for j in range(n):
for h in range(n):
print(i + j + h)
def print_to_zero(n):
if n < 0:
return
print(n)
print_to_zero(n - 1)
print_to_zero(5)
float("self-taught")
def get_input():
choices = ["rock", "paper", "scissors"]
uinput = input("Choose rock paper or scissors")
if uinput not in choices:
print("invalid option")
return
print("You picked {}".format(uinput))
return uinput
get_input()
import random
import string
def generate_function():
""" Returns a secure password."""
password = '' #The password starts as an empty string.
for i in range(random.randint(3, 5)): #We determine the length of the password by picking a random number between 3 and 5.
# Each time through the loop we add 4 characters to the string, so each password will be between 12 and 20 characters.
password += random.choice(string.punctuation) # The string module contains a variable called punctuation that
age = 20
@calthoff
calthoff / guess.py
Last active February 14, 2019 17:28
# list of correct number to guess
guess = [1,3,5]
while True:
question = input("Enter q for quit or guess a number")
if question == 'q':
break
try:
if int(question) in guess:
string = "hello"
# writing code that handles if whatever you are searching for isn't found with find
result = string.find("z"):
# This is bad because it is hard for another program to read
if result == -1:
raise ValueError("I couldn't find it")
print(result)
# writing code that handles if whatever you are searching for isn't found with index