This file contains 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 primer(number): | |
if number > 1: | |
for i in range(2, number): | |
if (number % i) == 0: | |
print(number, "isn't a prime") | |
break | |
else: | |
print(number, "is a prime") |
This file contains 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
# https://docs.python.org/3/library/timeit.html | |
import timeit | |
timeit.timeit("""name = "Annika" | |
... activity = "run" | |
... "Good Morning, %s! Let's go for a %s" % (name, activity)""", number = 10000) | |
timeit.timeit("""name = "Annika" | |
... activity = "run" |
This file contains 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
# Create a random list of 10000 integers | |
import random | |
randomlist = [] | |
for i in range(0,10000): | |
n = random.randint(1,30) | |
randomlist.append(n) | |
# Evaluate a simple calculation, print the random list using a for loop and determine the elapse time |
This file contains 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
for idx, num in enumerate(numbers): | |
if (num % 6) == 0 : | |
print("fizzbuzz", idx,num) | |
elif (num % 3) == 0: | |
print("buzz", idx, num) | |
elif (num % 2) == 0: | |
print("fizz", idx, num) |
This file contains 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
for i in range(len(numbers)): | |
if (numbers[i] % 6) ==0 : | |
print("fizzbuzz", i) | |
elif (numbers[i] % 3) == 0: | |
print("buzz",i) | |
elif (numbers[i] % 2) == 0: | |
print("fizz", i) | |
else: | |
pass |
This file contains 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 bracket_matcher(sample): | |
counter = 0 | |
for char in sample: | |
if char == '(': | |
counter += 1 | |
elif char == ')': | |
counter -= 1 | |
if counter == -1: | |
return(0) |
This file contains 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 bracket_matcher(sample): | |
left_bracket, right_bracket = 0,0 | |
for char in sample: | |
if char == '(': | |
left_bracket += 1 | |
elif char == ')': | |
right_bracket +=1 | |
This file contains 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 bracket_matcher(sample): | |
brackets = [')',']'] | |
flag = False | |
for bracket in brackets: | |
if bracket in sample: | |
flag = True | |
return flag |
This file contains 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 bracket_matcher(sample): | |
return ')' in sample |
This file contains 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 bracket_matcher(sample): | |
for char in sample: | |
if char == ')': | |
print('True') | |
else: | |
print('False') |