Last active
November 11, 2019 12:02
-
-
Save klamfa/8f03c3f10a286d80bb73d4045b335a6f to your computer and use it in GitHub Desktop.
Homework 4
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
all_hair_colors = {"black_hair": "CCAGCAATCGC", "brown_hair": "GCCAGTGCCG", "blonde_hair": "TTAGCTATCGC"} | |
all_face_shapes = {"square_face": "GCCACGG", "round_face": "ACCACAA", "oval_face": "AGGCCTCA"} | |
all_eye_colors = {"blue_eyes": "TTGTGGTGGC", "green_eyes": "GGGAGGTGGC", "brown_eyes": "AAGTAGTGAC"} | |
all_genders = {"female": "TGAAGGACCTTC", "male": "TGCAGGAACTTC"} | |
all_races = {"white": "AAAACCTCA", "black": "CGACTACAG", "asian": "CGCGGGCCG"} | |
eva = {"name": "Eva", "gender": "female", "race": "white", "hair_color": "blonde_hair", "eye_color": "blue_eyes", | |
"face_shape": "oval_face"} | |
larisa = {"name": "Larisa", "gender": "female", "race": "white", "hair_color": "brown_hair", "eye_color": "brown_eyes", | |
"face_shape": "oval_face"} | |
matej = {"name": "Matej", "gender": "male", "race": "white", "hair_color": "black_hair", "eye_color": "blue_eyes", | |
"face_shape": "oval_face"} | |
miha = {"name": "Miha", "gender": "male", "race": "white", "hair_color": "brown_hair", "eye_color": "green_eyes", | |
"face_shape": "square_face"} | |
all_atributes = [all_races, all_genders, all_eye_colors, all_face_shapes, all_hair_colors] | |
all_suspects = [eva, larisa, matej, miha] | |
list_of_atribute_sequences = [] | |
list_of_atribute_values = [] | |
with open('dna.txt', 'r') as dna_file: | |
dna_sequence = dna_file.read() | |
for atributes in all_atributes: | |
for atribute_sequence in atributes.values(): | |
if atribute_sequence in dna_sequence: | |
list_of_atribute_sequences.append(atribute_sequence) | |
for atributes in all_atributes: | |
for atribute, sequence in atributes.items(): | |
if sequence in list_of_atribute_sequences: | |
list_of_atribute_values.append(atribute) | |
for suspect in all_suspects: | |
matching_atributes = 0 | |
for item in list_of_atribute_values: | |
for atributes, atribute_value in suspect.items(): | |
if item == atribute_value: | |
matching_atributes +=1 | |
break | |
if matching_atributes == 5: | |
print(" DNA analisys complete.. The criminal is " + suspect.get("name") + "!!!!!") |
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 | |
import json | |
import datetime | |
secret = random.randint(1, 30) | |
attempts = 0 | |
wrong_guesses = [] | |
with open("scores_list.txt", "r") as score_file: | |
scores_list = json.loads(score_file.read()) | |
sorted_scores_list = sorted(scores_list, key=lambda k: k['attempts']) | |
for score_dict in sorted_scores_list[:3]: | |
print("Name: " + score_dict["player"] + ", " + "wrong guesses: " + str(score_dict.get("wrong guesses")) + ", " | |
+ str(score_dict["attempts"]) + " attempts, " + "secret number was " + str(score_dict.get("secret number")) + | |
", date: " + score_dict.get("date")) | |
players_name = str(input("What is your name? Type here:")) | |
while True: | |
guess = int(input("Guess the secret number (between 1 and 30): ")) | |
attempts += 1 | |
if guess == secret: | |
print("You've guessed it - congratulations! It's number " + str(secret)) | |
print("Attempts needed: " + str(attempts)) | |
current_time = datetime.datetime.now() | |
current_time = current_time.strftime("%d.%m.%Y, %H:%M:%S") | |
scores_list.append({"player": players_name, "attempts": attempts, "date": str(current_time), | |
"wrong guesses": wrong_guesses, "secret number": str(secret)}) | |
with open("scores_list.txt", "w") as score_file: | |
score_file.write(json.dumps(scores_list)) | |
break | |
elif guess > secret: | |
print("Your guess is not correct... try something smaller") | |
wrong_guesses.append(guess) | |
elif guess < secret: | |
print("Your guess is not correct... try something bigger") | |
wrong_guesses.append(guess) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excellent job with the Forensics_program.py! Kudos for solving it!
Homework_4-1_2_3.py: line 27
current_time
could becurrent_time_formatted
- otherwise this re-assigning of the variable is a bit confusing at first glance (and may introduce errors if you later decide to use the current_time variable since you don't know which "shape" it is in).Homework_4-1_2_3.py: line 28
Try to format each attribute of the dictionary into its own line - it's much easier to read.