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
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
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
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
list_ = [] | |
def divisor_check(): | |
num = int(input("Enter the number you wanna check:")) | |
divisor = 1 | |
for i in range(num): | |
if num % divisor == 0: | |
list_.append(divisor) | |
divisor += 1 | |
divisor_check() | |
print(list_) |
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
# part 1 | |
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
for item in a: | |
if item < 5: | |
print(item), | |
# part 2 | |
b = [item for item in a if item < 5] | |
print("\n") | |
print(b) |
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
number = int(input("Enter a number:")) | |
if number % 2 == 0 and number % 4 == 0: | |
print("%d is a multiple of both 2 and 4") % number | |
elif number % 2 == 0: | |
print("%d is an even number") % number | |
else: | |
print("%d is an odd number") % number | |
def num_check(): |
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 datetime | |
name = raw_input("Enter your name:") | |
age = int(input("Enter your age:")) | |
now = datetime.datetime.now() | |
year = now.year + (100 - age) | |
message = "Hey %s you will turn 100 years old in the year %d" %(name, year) | |
number = int(input("How many times would you like to print the message?")) | |
for i in range(number): | |
print message |
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
sample = ['GTA','GGG','CAC'] | |
def read_dna(dna_file): | |
dna_data = "" | |
with open(dna_file, "r") as f: | |
for line in f: | |
dna_data += line | |
return dna_data | |
def dna_codons(dna): |
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
"""This program creates a Python class tat can be used to create and manipulate a personal bank account. The Bank account class: accepts deposits, allows withdrawals, shows the balance and shows the details of the account.""" | |
class BankAccount(object): | |
balance = 0 | |
def __init__(self, name): | |
self.name = name | |
def __repr__(self): | |
return "This account belongs to %s and has a balance of $%.2f" %(self.name, self.balance ) | |
def show_balance(self): | |
print("%s's balance: $%.2f") %(self.name,\ |