Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reto #8 - Python #6468

Merged
merged 7 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed Images/header.jpg
Binary file not shown.
20 changes: 20 additions & 0 deletions Retos/Reto #10 - LA API [Media]/python/Paula2409.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""/*
* Llamar a una API es una de las tareas más comunes en programación.
*
* Implementa una llamada HTTP a una API (la que tú quieras) y muestra su
* resultado a través de la terminal. Por ejemplo: Pokémon, Marvel...
*
* Aquí tienes un listado de posibles APIs:
* https://github.com/public-apis/public-apis
*/
"""
import requests

def request_http():
request = requests.get('https://developer.oxforddictionaries.com/')
print(request.status_code) # prints 200 (ok)
print(request.headers) # print(headers of API)
print(request.json) # <bound method Response.json of <Response [200]>>
print(request.text) # text HTML and CSS

request_http()
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
/*
* Crea un programa que calcule quien gana más partidas al piedra,
* papel, tijera, lagarto, spock.
* - El resultado puede ser: "Player 1", "Player 2", "Tie" (empate)
* - La función recibe un listado que contiene pares, representando cada jugada.
* - El par puede contener combinaciones de "🗿" (piedra), "📄" (papel),
* "✂️" (tijera), "🦎" (lagarto) o "🖖" (spock).
* - Ejemplo. Entrada: [("🗿","✂️"), ("✂️","🗿"), ("📄","✂️")]. Resultado: "Player 2".
* - Debes buscar información sobre cómo se juega con estas 5 posibilidades.
*/
"""
game_rules = {
'🗿': ['🦎','✂️'], # rock crushes lizard and scissors
'📄': ['🗿','🖖'], # paper covers rock and invalidates spock
'✂️': ['📄','🦎'], # scissors cuts paper and beheads lizard
'🦎': ['🖖', '📄'], # lizard poison spock and eats paper
'🖖': ['✂️', '🗿'] # spock breaks scissors and crushes rock
}

def rock_paper_scissors(play):
"""
Determines the winner of a game based on the rules of
'rock, paper, scissors, lizard, spock'.

Args:
play(list): a list with the option of each player

Returns:
str: returns which player wins
"""
points_player1, points_player2 = 0,0
index_play = 0
while index_play < len(play):
if play[index_play][0] in game_rules[play[index_play][1]]:
points_player2 += 1
print(f'Points player 2: {points_player2}')
else:
points_player1 += 1
print(f'Points player 1: {points_player1}')

index_play += 1
if points_player1 > points_player2:
return 'Player 1'
elif points_player2 > points_player1:
return 'Player 2'
else:
return 'Tie'

print(rock_paper_scissors([("🗿","✂️"), ("✂️","🗿"), ("📄","✂️")]))


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import datetime

now = datetime.datetime.now().microsecond
print(now)
print(now%101)
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
/*
* Crea 3 funciones, cada una encargada de detectar si una cadena de
* texto es un heterograma, un isograma o un pangrama.
* - Debes buscar la definición de cada uno de estos términos.
*/
"""
import string

def evaluate_text():
"""
The function evaluates whether a given text is a heterogram, isogram, or pangram based on the
occurrence of letters in the text.

Args:
text (str): any text given by user

Returns:
str: returns if the text is a heterogram, an isogram and a pangram.
"""
# Input a word or phrase
text = input("Ingrese un texto o palabra para evaluar: ")
# Process the input
new_text = text.lower().replace('á', 'a').replace('é', 'e').replace('í', 'i').replace('ó', 'o').replace('ú', 'u').replace(' ', '')
simbols = string.punctuation

letters_present = {}

for char in new_text:
if char in simbols:
new_text = new_text.replace(char, "")
else:
if char in letters_present:
letters_present[char] += 1
else:
letters_present[char] = 1

values = list(letters_present.values())

def is_heterogram():
# Heterogram: is a word, phrase or sentence in which no letter of the alphabet occurs more than once.
if len(set(values)) == 1:
return f"The text '{text}' is a heterogram"
else:
return f"The text '{text}' is not a heterogram"


def is_isogram():
# Isogram: word or phrase in which each letter occurs the same number of times.
for value in values:
if value != values[0]:
return f"The text '{text}' is an Isogram"
return f"The text '{text}' is not an Isogram"

def is_pangrama():
# Pangrama: word, phrase or sentence in which all letters of the alphabet are present.
letters = list(string.ascii_lowercase) + ['ñ']
for letter in letters:
if letter in text:
letters.remove(letter)
if len(letters) == 0:
return f"The text '{text}' is a pangram"
else:
return f"The text '{text}' is not a pangram"

print(is_heterogram())
print(is_isogram())
print(is_pangrama())

evaluate_text()