Skip to content

Instantly share code, notes, and snippets.

View odanga94's full-sized avatar

Odanga Ochieng' odanga94

  • Kenya
View GitHub Profile
@odanga94
odanga94 / Exercise28.py
Last active October 25, 2019 16:15
PracticePython/Exercise28
numbers = [70, 55, 100.5]
def max_(numbers):
greatest = numbers[0]
for x in numbers:
if x > greatest:
greatest = x
print(greatest)
max_(numbers)
@odanga94
odanga94 / Exercise33.py
Created May 28, 2017 11:46
PracticePython/Exercise33
def birthday_lookup():
birthdays = {"Albert Einstein": "14/03/1879", \
"Benjamin Franklin": "17/01/1706", "Ada Lovelace": "10/12/1815"}
print("Welcome to the birthday dictionary. We know the birthdays of: \
\nAlbert Einstein\nBenjamin Franklin\nAda Lovelace")
look_up = raw_input("Who's birthday do you want to look up? ")
print("%s's birthday is %s.") %(look_up, birthdays.get(look_up, "there is no such person in our dictionary"))
check_birthday = "y"
while check_birthday == "y":
@odanga94
odanga94 / Exercise24.py
Created May 22, 2017 16:17
PracticePython/Exercise24
def draw_board():
n = int(raw_input("Enter the board size you want: "))
if n == 1:
print(" ---")
print("| |")
print(" ---")
else:
for i in range(n):
print(""),
@odanga94
odanga94 / Exercise18.py
Created May 16, 2017 05:56
PracticePython/Exercise18.py
import random
def play():
true_value = str(random.randint(1000, 9999))
guesses = 0
play = 'y'
while play == 'y':
cows = 0
bulls = 0
@odanga94
odanga94 / Exercise16.py
Created May 14, 2017 12:07
PracticePython/Exercise16
import random
import string
lower_case = set(string.ascii_lowercase)
upper_case = set(string.ascii_uppercase)
digits = set(string.digits)
special_char = set(string.punctuation)
def password_generator():
length = int(raw_input("How long a password do you want (at least 4)? "))
password = set(random.sample((lower_case | upper_case | digits | special_char), length))
@odanga94
odanga94 / Exercise15.py
Created May 13, 2017 15:59
PracticePython/Exercise15.py
def reverse():
original = raw_input("Enter a string containing multiple words:")
reverse = " ".join(original.split()[::-1])
print(reverse)
reverse()
@odanga94
odanga94 / Exercise13.py
Created May 13, 2017 08:14
Fiboncacci/Exercise13.py
def fibonacci(): # where n is the nth number of the Fibonacci sequence the function will generate
fib_list = []
fib_1 = 1 # by definition the first two numbers in the Fibonacci sequence are both 1
n = int(input("How many numbers in the Fibonacci sequence would you like to generate? "))
if n == 1 or n ==2:
for i in range(n):
fib_list.append(fib_1)
else:
for i in range(2):
@odanga94
odanga94 / Exercise12.py
Created May 13, 2017 07:11
PracticePython/Exercise12
a = [0, 5, 10, 15, 20, 25, 75]
def new_list(a):
new = []
new.append(a[0])
new.append(a[len(a) - 1])
print(new)
new_list(a)
@odanga94
odanga94 / Exercise11.py
Created May 12, 2017 16:44
PracticePython/Exercise11.py
def is_prime():
num = int(input("Enter the number you wanna check:"))
divisor = 2
while num != divisor:
if num == 1:
print(False)
break
elif num % divisor == 0:
print(False)
break
@odanga94
odanga94 / Exercise9.py
Created May 12, 2017 15:24
PracticePython/Exercise9
from random import randint
true_value = randint(1, 9)
print(true_value)
count = 0
while True:
user_guess = int(input("Guess a number between 1 and 9: "))
count += 1
if user_guess == true_value:
print("You guess was correct. Congratulations!!")
break