Skip to content

Commit a6545f1

Browse files
committed
Tast 1-7
0 parents  commit a6545f1

7 files changed

+120
-0
lines changed

DifferenceOfSquares.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sum = 0
2+
sums_squared = 0
3+
for x in range(1, 11):
4+
sum += x
5+
sums_squared = sum**2
6+
print("Sum of first 10 natural numbers squared: ", sums_squared)
7+
sum = 0
8+
for x in range(1, 11):
9+
sum += x**2
10+
print("Sum of squares of first 10 natural numbers: ", sum)
11+
print("Difference between square of the sum and sum of the squares is:", sums_squared - sum)

Gigasecond.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import datetime
2+
print("Please enter your date of birth:")
3+
print("Day")
4+
day = input()
5+
print("Month")
6+
month = input()
7+
print("Year")
8+
year = input()
9+
10+
date = datetime.date(int(year), int(month), int(day))
11+
b = date.replace(year=date.year + 31, month=date.month + 8, day=date.day + 15) # Closest i could get it without it getting annoying.
12+
print("One gigasecond later...", b)

HelloWorld.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
print('Whats your name?')
2+
name = input()
3+
if not name:
4+
print('Hello World!')
5+
else:
6+
print(f'Hello {name}!')

Panagram.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sentence = input()
2+
# to lower, remove duplicate characters
3+
# Will not work if string contains numbers/special characters
4+
if len(sorted("".join(set((sentence.lower()))))) == 27:
5+
print('Thats a panagram!')
6+
else:
7+
print('Thats not a panagram :(')

RLE.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def rle_encode(input):
2+
output = ''
3+
last_char = ''
4+
count = 1
5+
6+
if not input: return ''
7+
8+
for char in input:
9+
if char != last_char:
10+
if last_char:
11+
output += str(count) + last_char
12+
count = 1
13+
last_char = char
14+
else:
15+
count += 1
16+
else:
17+
output += str(count) + last_char
18+
return output
19+
20+
print(rle_encode(input()))

Rna.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
print("Please input DNA strand")
2+
dna = input()
3+
4+
# RNA codon table
5+
rna_codon = {"UUU" : "F", "CUU" : "L", "AUU" : "I", "GUU" : "V",
6+
"UUC" : "F", "CUC" : "L", "AUC" : "I", "GUC" : "V",
7+
"UUA" : "L", "CUA" : "L", "AUA" : "I", "GUA" : "V",
8+
"UUG" : "L", "CUG" : "L", "AUG" : "M", "GUG" : "V",
9+
"UCU" : "S", "CCU" : "P", "ACU" : "T", "GCU" : "A",
10+
"UCC" : "S", "CCC" : "P", "ACC" : "T", "GCC" : "A",
11+
"UCA" : "S", "CCA" : "P", "ACA" : "T", "GCA" : "A",
12+
"UCG" : "S", "CCG" : "P", "ACG" : "T", "GCG" : "A",
13+
"UAU" : "Y", "CAU" : "H", "AAU" : "N", "GAU" : "D",
14+
"UAC" : "Y", "CAC" : "H", "AAC" : "N", "GAC" : "D",
15+
"UAA" : "STOP", "CAA" : "Q", "AAA" : "K", "GAA" : "E",
16+
"UAG" : "STOP", "CAG" : "Q", "AAG" : "K", "GAG" : "E",
17+
"UGU" : "C", "CGU" : "R", "AGU" : "S", "GGU" : "G",
18+
"UGC" : "C", "CGC" : "R", "AGC" : "S", "GGC" : "G",
19+
"UGA" : "STOP", "CGA" : "R", "AGA" : "R", "GGA" : "G",
20+
"UGG" : "W", "CGG" : "R", "AGG" : "R", "GGG" : "G"
21+
}
22+
23+
rna = ""
24+
25+
for i in dna:
26+
if i == "T":
27+
rna += "U"
28+
else:
29+
rna += i
30+
31+
print("RNA strand", rna)
32+
print("Would you like to convert to protein sequence? Yes/No")
33+
34+
def generate_protein():
35+
protein_string = ""
36+
37+
for i in range(0, len(rna)-(3+len(rna)%3), 3):
38+
if rna_codon[rna[i:i+3]] == "STOP" :
39+
break
40+
protein_string += rna_codon[rna[i:i+3]]
41+
42+
# Print the protein string
43+
print( "Protein String: ", protein_string)
44+
45+
if input().lower() == "yes":
46+
generate_protein()
47+
48+
49+
# source: https://towardsdatascience.com/starting-off-in-bioinformatics-rna-transcription-and-translation-aaa7a91db031

WordCount.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def word_count(str):
2+
counts = dict()
3+
words = str.split()
4+
5+
for word in words:
6+
if word in counts:
7+
counts[word] += 1
8+
else:
9+
counts[word] = 1
10+
11+
return counts
12+
13+
print(word_count(input()))
14+
15+
# definitely did not find this script here https://www.w3resource.com/python-exercises/string/python-data-type-string-exercise-12.php

0 commit comments

Comments
 (0)