This file contains hidden or 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
numbers = [70, 55, 100.5] | |
def max_(numbers): | |
greatest = numbers[0] | |
for x in numbers: | |
if x > greatest: | |
greatest = x | |
print(greatest) | |
max_(numbers) |
This file contains hidden or 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 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": |
This file contains hidden or 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 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(""), |
This file contains hidden or 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
import random | |
def play(): | |
true_value = str(random.randint(1000, 9999)) | |
guesses = 0 | |
play = 'y' | |
while play == 'y': | |
cows = 0 | |
bulls = 0 |
This file contains hidden or 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
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)) |
This file contains hidden or 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 reverse(): | |
original = raw_input("Enter a string containing multiple words:") | |
reverse = " ".join(original.split()[::-1]) | |
print(reverse) | |
reverse() |
This file contains hidden or 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 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): |
This file contains hidden or 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
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) |
This file contains hidden or 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 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 |
This file contains hidden or 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 | |
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 |
NewerOlder