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
a = int(input("Side a = ")) | |
b = int(input("Side b = ")) | |
c = int(input("Side c = ")) | |
sides = [] | |
sides.append(a) | |
sides.append(b) | |
sides.append(c) | |
sides.sort() |
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
from functools import lru_cache | |
@lru_cache(maxsize = 1000) | |
# default is 128 values | |
def fibonacci3(n): | |
if n == 1 or n == 2: | |
return 1 | |
elif n > 2: | |
return fibonacci3(n-1) + fibonacci3(n-2) |
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
import random | |
def random_walk2(n): | |
"""n number of blocks to walk""" | |
x, y = 0, 0 | |
for i in range(1, n): | |
(dx, dy) = random.choice([(0, 1), (0, -1), (-1, 0), (1, 0)]) | |
x = x + dx | |
y = y + dy |
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
movies2 = [("SW", 1992), ("GWR", 1999), ("PIY", 2010), ("AGE", 2015), | |
("GIT", 1995), ("BUT", 1970), ("GGG", 2001)] | |
pre2k = [i[0] for i in movies2 if i[1] < 2000] | |
print(pre2k) | |
pre2k2 = [title for (title, year) in movies2 if year < 2000] | |
print(pre2k2) |
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
#Write a program which will find all such numbers which are divisible | |
# by 7 but are not a multiple of 5, | |
#between 2000 and 3200 (both included). | |
#The numbers obtained should be printed in a comma-separated sequence | |
#on a single line. | |
by7_notby5 = [i for i in range(2000, 3201) if (i % 7 == 0) and (i % 5 != 0)] | |
print(by7_notby5) |
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
#Write a program which can compute the factorial of a given numbers. | |
#The results should be printed in a comma-separated sequence on a single line. | |
def factorial(n): | |
value = 1 | |
for i in range(1, n+1): | |
value = value * i | |
return value | |
number = int(input("Type a number: ")) |
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
number = int(input("Type a number: ")) | |
numberDict = {} | |
for i in range(1, number+1): | |
numberDict[i] = i*i | |
print(numberDict) |
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
numbers = input("Type in numbers seperated only by a comma :") | |
numbers_split = numbers.split(',') | |
number_tuple = tuple(numbers_split) | |
print(number_tuple) | |
print(numbers_split) |
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
import math | |
numbers = input("Provide D: ") | |
numbers = numbers.split(',') | |
result_list = [] | |
for D in numbers: | |
Q = round(math.sqrt(2 * 50 * int(D) / 30)) | |
result_list.append(Q) |
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
phrase = input("Input words: ") | |
phrase_list = phrase.split(",") | |
phrase_list.sort() | |
print((', ').join(phrase_list)) |
OlderNewer