Last active
May 24, 2021 09:37
-
-
Save Skydrifa/32b31d8e58c974baa29df6d94ad8e3ee to your computer and use it in GitHub Desktop.
este_11este_11
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
ACAAGATGCCATTGTCCCCCGGCCTCCTGCTGCTGCTGCTCTCCGGGGCCACGGCCACCGCTGCCCTGCCCCTGGAGGGTGGCCCCACCGGCCGAGACAGCGAGCATATGCAGGAAGCGGCAGGAATAAGGAAAAGCAGCCTCCTGACTTTCCTCGCTTGGTGGTTTGAGTGGACCTCCCAGGCCAGTGCCGGGCCCCTCATAGGAGAGGAAGCTCGGGAGGTGGCCAGGCGGCAGGAAGGCGCACCCCCCCAGCAATCCGCGCGCCGGGACAGAATGCCCTGCAGGAACTTCTTCTGGAAGACCTTCTCCTCCTGCAAATAAAACCTCACCCATGAATGCTCACGCAAGTTTAATTACAGACCTGAA |
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 main | |
print("Bem-vindo ao jogo 'SmartNinja'.") | |
main.menu_entrada() |
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
# DNA exercise: 11 + 12 + 13 listas + funções + oop | |
# Search for value in the dictionary with multiple values for a key | |
# THERE IS TWO WAYS TO DO THIS: | |
# FIRST CHARACTERISTICS ARE SEPARETED ON DICTS (COLOR: DNA) | |
# THE SECRET IS HOW EASILY YOU STORE YOUR DATA ON LIST, DICTS OR TUPLES | |
# LET'S SEE MY FIRST VERSION ... THERE IS A LOT OF POSSIBLITIES IN THE WAY YOU STORE YOUR DATA | |
import random | |
# import datetime | |
# import json | |
import suport_Object_class | |
# import re | |
suspects = { "eva" : ["female", "white", "blonde", "blue", "oval"], | |
"larisa" : ["female", "white", "brown", "brown", "oval"], | |
"matej" : ["male", "white", "black", "blue", "oval"], | |
"miha" : ["male", "white", "brown", "green", "square"]} | |
hair = {"black" : "CCAGCAATCGC", "brown" : "GCCAGTGCCG", "blonde" : "TTAGCTATCGC"} | |
face = {"square" : "GCCACGG", "round" : "ACCACAA", "oval" : "AGGCCTCA"} | |
eyes = {"blue" : "TTGTGGTGGC", "green" : "GGGAGGTGGC", "brown" : "AAGTAGTGAC"} | |
gender = {"female" : "TGAAGGACCTTC", "male" : "TGCAGGAACTTC"} | |
race = {"white" : "AAAACCTCA", "black" : "CGACTACAG", "asian" : "CGCGGGCCG"} | |
# hair = hair.values() | |
# face = face.items() | |
# eyes = eyes.items() | |
# gender = gender.items() | |
# race = race.items() | |
# map each person to a list in a dict of properties describing the person at hand... | |
# mind that the order of properties in the list is important :::: for dictionary in mylist['mydict']: | |
suspects_dna = {"eva": ["TGAAGGACCTTC", "AAAACCTCA", "TTAGCTATCGC", "TTGTGGTGGC", "AGGCCTCA"], | |
"larisa": ["TGAAGGACCTTC", "AAAACCTCA", "GCCAGTGCCG", "AAGTAGTGAC", "AGGCCTCA"], | |
"matej": ["TGCAGGAACTTC", "AAAACCTCA", "CCAGCAATCGC", "TTGTGGTGGC", "AGGCCTCA"], | |
"miha": ["TGCAGGAACTTC", "AAAACCTCA", "GCCAGTGCCG", "GGGAGGTGGC", "GCCACGG"]} | |
brown_dna_hair = { | |
"larisa": ["TGAAGGACCTTC", "AAAACCTCA", "GCCAGTGCCG", "AAGTAGTGAC", "AGGCCTCA"], | |
"miha": ["TGCAGGAACTTC", "AAAACCTCA", "GCCAGTGCCG", "GGGAGGTGGC", "GCCACGG"]} | |
# read the dna file to verify | |
with open("dna.txt", "r") as dna_file: | |
dna = dna_file.read() | |
class Result: | |
def __init__(self, hair, face, eyes, gender, race): | |
self.hair = hair | |
self.face = face | |
self.eyes = eyes | |
self.gender = gender | |
self.race = race | |
# self.date = date | |
# suspect_file = "suspect_list.json" | |
# Create blank list to append to | |
questinary_suspect = [] | |
def menu_entrada(): | |
print("Selecione a opção: ") | |
crime_mode = input("\nA) Descobriu um cabelo no local do crime? \nB) Consultar no laboratório o ADN no local do crime,... \nC) Did you see the suspect, describe it,... \nD) Qualquer tecla para sair: \n:") | |
if crime_mode.lower() == "a": | |
hair_level() | |
elif crime_mode.lower() == "b": | |
dna_level() | |
elif crime_mode.lower() == "c": | |
physical_level() | |
else: | |
print("Obrigado por ter vindo.") | |
def hair_level(): | |
level = input("\nA) Qual a cor do cabelo?: \nB) Colocar o DNA do cabelo:" | |
" \nC) Qualquer tecla para voltar para menu anterior \n:") | |
if level.lower() == "a": | |
game_easy_level1() | |
elif level.lower() == "b": | |
dna_level() | |
else: | |
menu_entrada() | |
def game_easy_level1(): | |
# now we check properties in the same order | |
# Iterate over a dictionary with list values using nested for loop | |
# Iterate over a dictionary with list values and create | |
# YOU HAVE THE POSSILITIE FOR a pair of all key-value pairs. | |
# suspect_list = get_suspect_list() | |
# Check if a value exist in dictionary with multiple value | |
user_guess = input('Qual a cor do cabelo: ' ) # print '%s %d' % (name, number) neste caso (key, value) | |
# Get list of keys that contains the given value - key is name | |
list_of_keys = [key | |
for key, list_of_values in suspects.items() | |
if user_guess in list_of_values] | |
print('Cabelo caracteristico de :', list_of_keys) | |
print([suspects[x] for x in list_of_keys]) | |
# split dictionary into keys and values | |
# keys = suspects.keys() | |
# values = suspects.values() | |
# print the values: | |
# print("Dict key-value are : ") | |
# for x in suspects: | |
# print(x, suspects[x]) | |
#for name in len(list_of_keys): | |
#print('Cabelo caracteristico de :', name) | |
# print(suspects.items()) #['female', 'white', 'blonde', 'blue', 'oval'] | |
# Nested list | |
# Each value is itself a list, so we need another for loop | |
# to work with the list: | |
# Each value is itself a list, so let's put that list in a variable. | |
# current_suspects = suspects[name] | |
# using naive method to | |
# perform conversion | |
# using list comprehension to | |
# perform conversion count the number of names in the list for a number is len | |
dictionary_length = len(list_of_keys) | |
if dictionary_length == 2: | |
dna_te = hair.get(input('There is two people with the same hair. Put the hair on the machine, to color:')) | |
print("Dna of brown hair is: ", dna_te) | |
# to avoid two people with the same color you need to have the DNA of the hair | |
# AQUI QUERIA FAZER UM MATCH OU FILTER DO HAIR.GET NO VALUE DO DICT OF SUSPECTS_DNA E NÃO ESTAR A FAZER UMA DICT PARA QUEM JÁ TEM APENS BROWN HAIR | |
random_dna = random.choice(list(brown_dna_hair.items())) | |
# fetch value using key name | |
print("DNA conresponde a: ", str(random_dna)) | |
print("É como:") | |
# não consegue usar o random_dna | |
key_of_random_dna = random_dna[0] | |
if key_of_random_dna in suspects: | |
print(suspects[key_of_random_dna]) | |
# How to check if keys exists and retrieve value from Dictionary in descending priority | |
# print([suspects[x] for x in random_dna.values()]) | |
# how to filter out all user dictionaries that don’t meet the condition of having a key | |
# print("Match Found: ", [value for value in suspects_dna.values()][1]) | |
# get_suspect_list() | |
# with open(suspect_file, "r") as score_file: | |
# score_file.write(json.dumps(suspect_list)) | |
# print("A informacao do suspeito foi guardada no ficheiro ") | |
# get the caractristics of suspect | |
elif dictionary_length == 1: | |
# list out keys and values separately | |
print([suspects[x] for x in list_of_keys]) | |
# get_suspect_list() # get the cractristics of suspect | |
# else: | |
#print("You have discover the suspect") | |
# print and write append on the file of the suspect caracteristics on true | |
# with open(suspect_file, "r") as score_file: | |
# score_file.write(json.dumps(suspect_list)) | |
# print("A informacao do suspeito foi guardada no ficheiro") | |
else: | |
print("Não existe essa cor!") | |
menu_entrada() | |
# now we have a description of our suspect, | |
# so now check who corresponds to this description... | |
# def game_easy_level2(): | |
# for p in suspects: | |
# if suspects[p] == suspect: | |
# print("The person we're looking for is %s" % p.upper()) | |
# break | |
def dna_level(): | |
# now we check properties in the same order | |
dna_sequence = random.choice(list(suspects_dna.items())) | |
print("The Dna of the person: ", dna_sequence) | |
# now we check properties DNA on the dna.txt, a variavel tem de ter um match na dict e possiveis nãos, aqui só tendo uma base de dados com várias possibilidades pode dar a inocencia (desconhecidos) | |
for suspect_x in suspects_dna: | |
for matching_dna in suspects_dna[suspect_x]: | |
if matching_dna in dna: # read the dna file to have innocent | |
print("Match found na base de dados policial!, ", dna_sequence) | |
key_found_dna = dna_sequence[0] | |
if key_found_dna in suspects: | |
print("Tem caracteristicas como: " + str(suspects[key_found_dna])) | |
exit() | |
# get_suspect_list() | |
if suspect_x not in dna: | |
print("Suspeito inocente!") | |
menu_entrada() | |
break | |
# for k, v in hair.items(): | |
# if k == key: | |
# print(v) | |
# game_easy_level2() | |
else: | |
print("Não existe match!") | |
menu_entrada() | |
def physical_level(): | |
# tenho de fazer for na função se não só entrega um resultado que é o objecto retrieve da função | |
print("Vamos descrever o sujeito pelas suas caracteristicas para o nosso retrato robô:") | |
caracteristicas_sequence = list(suspects.items()) | |
print(caracteristicas_sequence) | |
for suspect_y in suspects: | |
questinary_suspect = suport_Object_class.ask_data_comum() | |
# data_actual = datetime.datetime.today().ctime() | |
questinary_suspect = Result(hair=questinary_suspect[0], face=questinary_suspect[1], eyes=questinary_suspect[2], gender=questinary_suspect[3], race=questinary_suspect[4]) | |
# convert objects on a dict to be iterative | |
iterator = questinary_suspect.__dict__ | |
print(iterator) # {'hair': 'brown', 'face': 'oval', 'eyes': 'brown', 'gender': 'female', 'race': 'white'} | |
values_iterator = iterator.values() # retrieve dictionary values | |
values_iterator_list = list(values_iterator) # convert to list | |
print(values_iterator_list) # ['brown', 'oval', 'brown', 'female', 'white'] | |
for matching_cara in suspects[suspect_y]: | |
if matching_cara in caracteristicas_sequence: | |
print("Suspect is: " + str(suspects[suspect_y])) | |
exit() | |
matching_chord = {suspect for suspect in suspects} # {'larisa', 'miha', 'eva', 'matej'} | |
print(matching_chord) | |
matching_chord_2 = {suspect: [] for suspect in suspects} # {'eva': [], 'larisa': [], 'matej': [], 'miha': []} | |
print(matching_chord_2) | |
matching_chord_3 = {suspect for suspect in suspects} # {'eva': [], 'larisa': [], 'matej': [], 'miha': []} | |
print(matching_chord_3) | |
# else: | |
# print("no MATCHING!") | |
# return physical_level(hair, face, eyes, gender, race, data_actual) | |
# for user in suspects: | |
# if user == suspects.values(): | |
# matching = [key for key, val in suspects if questinary_suspect in key] | |
# print("O suspeito tem características do: " + name) | |
# data_actual = datetime.datetime.today().ctime() | |
# questinary_object = Result(hair=questinary_suspect[1], face=questinary_suspect[2], eyes=questinary_suspect[3], gender=questinary_suspect[4], race=questinary_suspect[5], date=str(data_actual)) | |
# suspect_data = questinary_object.__dict__ # will represent our suspects [] ... | |
# with open("suspect_list.json", "a") as score_file: | |
# score_list = json.loads(score_file.read()) | |
# score_list.write(json.dumps(score_file)) | |
# Get a list suspect | |
# def get_suspect_list(): | |
# with open("suspect_list.json", "a") as score_file: | |
# score_list = json.loads(score_file.read()) | |
# score_list.write(json.dumps(score_file)) | |
# return score_list | |
def another(): | |
rerun = input("Outro jogo? (S) para Sim ou (N) para não: ") | |
if rerun.lower() == "s": | |
menu_entrada() | |
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 ask_data_comum(): | |
questao_suspeito = ["Qual o cabelo do suspeito? ", "Qual a face? ", "Quais os olhos? ", "Qual seu gênero? ", "Qual a raça? "] | |
r_comuns = [] | |
for one in range(1, 5): | |
r_comuns.append(input(questao_suspeito[one])) | |
return r_comuns |
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
[] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment