Skip to content

Commit d028511

Browse files
committed
More code
1 parent a6545f1 commit d028511

7 files changed

+97
-0
lines changed

Allergies.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
score = input()
2+
def allergy(score):
3+
allergylist = ["cats", "pollen", "chocolate", "tomatoes", "strawberries", "shellfish", "peanuts", "eggs"]
4+
score = list((bin(score)[2:]).zfill(len(allergylist)))
5+
for j, i in enumerate(score):
6+
if i == "1":
7+
print ("You are allergic to : " + allergylist[j])
8+
9+
allergy(int(score))

Anagram.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
print("Given word:")
2+
word = input()
3+
print("Candidates")
4+
candidates = input()
5+
6+
def findAnagram(candidates):
7+
anagrams = []
8+
for candidate in candidates:
9+
if len(candidate) == len(word):
10+
sorted_word = sorted(word)
11+
sorted_candidate = sorted(candidate)
12+
if sorted_word == sorted_candidate:
13+
anagrams.append(candidate)
14+
return anagrams
15+
16+
print(f"List of anagrams matching {word}", findAnagram(candidates.split()))

Atbash.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Atbash:
2+
def solve(self, text):
3+
N = ord('z') + ord('a')
4+
noWhiteSpace = text.replace(" ", "")
5+
ans = ''
6+
b = ans.join([chr(N - ord(s)) for s in noWhiteSpace])
7+
return ' '.join([b[i:i+5] for i in range(0, len(b), 5)])
8+
ob = Atbash()
9+
print(ob.solve("abcdefg"))
10+
print(ob.solve("hello my name is arno does this actually work"))

GradeSchool.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import cast
2+
3+
4+
students = {3 : "Isaac", 2 : "Kenny", 1 : "Judith", 3 : "Pam", 1 : "Lewis", 2 : "Archer"}
5+
6+
while True:
7+
print("To see a list of commands, type '?'")
8+
command = input().lower()
9+
match command:
10+
case "?":
11+
print("add: add a student. Usage: add <name> <grade>")
12+
print("getGrade: gets all students in specified grade. Usage: getGrade <number>")
13+
print("getAll: gets all students in all grades.")
14+
case "add":
15+
name = input("Student Name: ")
16+
grade = input("Student grade: ")
17+
students[name] = grade
18+
case "all":
19+
for i in sorted (students.keys()) :
20+
print(i, end = " ")

RobotSim.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
instructions = "RAALAL"
2+
coords = [7, 3]
3+
direction = "north"
4+
def move(instructions, coords, direction):
5+
compass = ["north", "east", "south", "west"]
6+
direction = compass.index(direction)
7+
for action in instructions:
8+
match action:
9+
case 'A':
10+
match direction:
11+
case 0:
12+
coords[0] += 1
13+
case 1:
14+
coords[1] += 1
15+
case 2:
16+
coords[0] -= 1
17+
case 3:
18+
coords[1] -= 1
19+
case 'R':
20+
direction = (direction + 1) % 4
21+
case 'L':
22+
direction = (direction - 1) % 4
23+
24+
print(coords, "facing", compass[direction])
25+
26+
move(instructions, coords, direction)

Series.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
digits = input()
2+
K = 3
3+
# Extract K length substrings
4+
# Using list comprehension + string slicing
5+
res = [digits[i: j] for i in range(len(digits)) for j in range(i + 1, len(digits) + 1) if len(digits[i:j]) == K]
6+
7+
print("All K length substrings of string are : " + str(res))

SumOfMultiples.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
n = 3
2+
total = []
3+
sum = 0
4+
for i in range(1, 11):
5+
total.append(n * i)
6+
print(total)
7+
for i in total:
8+
sum += i
9+
print(sum)

0 commit comments

Comments
 (0)