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 | |
import sys | |
# Part 1 | |
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] | |
c = [] | |
def merge(): | |
for item in a: | |
if item in b and item not in c: | |
c.append(item) |
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
string = raw_input("Enter the string to test:") | |
string = string.lower() | |
backwards = [] | |
index = len(string) - 1 | |
while index >= 0: | |
backwards.append(string[index]) | |
index -= 1 | |
string_backwards = "".join(backwards) | |
if string == string_backwards: | |
print(True) |
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 = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] | |
c = [x for x in a if x % 2 == 0] | |
print(c) |
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 validate_input(player_choice): | |
if player_choice != "r" and player_choice != "p" and\ | |
player_choice != "s": | |
print("The input was invalid. Please input 'r', 'p' or 's'") | |
return False | |
else: | |
return True | |
def winner(player_1_choice, player_2_choice): | |
if player_1_choice == player_2_choice: |
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 |
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
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 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
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
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)) |