Created
May 2, 2021 21:57
-
-
Save Skydrifa/15e2cdc4fc68309bdfc47d765e972d0d to your computer and use it in GitHub Desktop.
List, Dict _
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
# Homework 11: DNA (person) + Country Capital | |
# devemos de estudar como chamar dict's e list : | |
# https://www.datacamp.com/community/tutorials/f-string-formatting-in-python?utm_source=adwords_ppc&utm_campaignid=898687156&utm_adgroupid=48947256715&utm_device=c&utm_keyword=&utm_matchtype=b&utm_network=g&utm_adpostion=&utm_creative=229765585183&utm_targetid=dsa-429603003980&utm_loc_interest_ms=&utm_loc_physical_ms=1011781&gclid=CjwKCAjwm7mEBhBsEiwA_of-TBkwp8iKmqtG3hwEqGRg6xtc665FNQhdzB9jfiC4N4vuNbdDzOmcsBoCfs4QAvD_BwE | |
import random | |
countries_cities = {"Austria": "Vienna", "Croatia": "Zagreb", "Spain": "Madrid", "Slovenia": "Ljubljana"} # dict <key>: <value>, # create a dictionary, key is the state and value is the capital | |
question = list(countries_cities.keys()) # colocar a lista para poder separá-la. há o keys, values e o items | |
point = 0 | |
for i in range(10): # randomly select 10 countries, how do I avoid duplicate? | |
state = random.choice(question) # separar capital e país | |
capital = countries_cities[state] | |
user_guess = input('What is the capital of %s?' %state) # print '%s %d' % (name, number) neste caso (key, value) | |
if user_guess.lower() == capital: | |
point += 1 | |
print('Correct! Your score is %d' %point) | |
else: # string.format(value1, value2...) | |
print('Incorrect. The capital of {} is {}.'.format(state, capital)) # The format() method formats the specified value(s) and insert them inside the string's placeholder. | |
print('We are done. Your final score is %d, thank you.' %point) # print '%s %d' % (name, number) print('%s %s %d %f %g' % (name, number, number, number, number)) | |
# formatting strings. %s acts a placeholder for a string while %d acts as a placeholder for a number. Their associated values are passed in via a tuple using the % operator. |
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
# Homework 11: DNA (person) + Country Capital | |
# devemos de estudar como chamar dict's e list : | |
# https://www.datacamp.com/community/tutorials/f-string-formatting-in-python?utm_source=adwords_ppc&utm_campaignid=898687156&utm_adgroupid=48947256715&utm_device=c&utm_keyword=&utm_matchtype=b&utm_network=g&utm_adpostion=&utm_creative=229765585183&utm_targetid=dsa-429603003980&utm_loc_interest_ms=&utm_loc_physical_ms=1011781&gclid=CjwKCAjwm7mEBhBsEiwA_of-TBkwp8iKmqtG3hwEqGRg6xtc665FNQhdzB9jfiC4N4vuNbdDzOmcsBoCfs4QAvD_BwE | |
import random | |
countries_cities = {"Austria": "Vienna", "Croatia": "Zagreb", "Spain": "Madrid", "Slovenia": "Ljubljana"} # dict <key>: <value>, # create a dictionary, key is the state and value is the capital | |
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"} | |
people = {"eva" : ["female", "white", "blonde", "blue", "oval"], | |
"larisa" : ["female", "white", "brown", "brown", "oval"], | |
"matej" : ["male", "white", "black", "blue", "oval"], | |
"miha" : ["male", "white", "brown", "green", "square"]} | |
# caracteristicas = {str(hair), str(face), str(eyes), str(gender), str(race)} é o que está em cima | |
question = list(people.keys()) # colocar a lista para poder separá-la. há o keys, values e o items | |
point = 0 | |
# read the dna file | |
with open("dna.txt", "r") as dna_file: | |
dna = dna_file.read() | |
for i in range(10): # randomly select 10 countries, how do I avoid duplicate? | |
hair = random.choice(question) # separar capital e país | |
person = people[hair] | |
user_guess = input('What is the hair of %s?' %hair) # print '%s %d' % (name, number) neste caso (key, value) | |
if user_guess.lower() == person: | |
point += 1 | |
print('Correct! Your score is %d' %point) | |
else: # string.format(value1, value2...) | |
print('Incorrect. The {} is {}.'.format(hair, person)) # The format() method formats the specified value(s) and insert them inside the string's placeholder. | |
# formatting strings. %s acts a placeholder for a string while %d acts as a placeholder for a number. Their associated values are passed in via a tuple using the % operator. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment