---
title: "Python scripts repo"
url: "https://fcuba.net/threads/9237-python-scripts-repo"
forum: "Informática y Tecnología"
author: "Miembro 1506"
published: "2023-03-22T06:16:01.000Z"
updated: "2023-03-26T18:53:31.000Z"
page: 1
pages: 1
---

# Python scripts repo

In [Informática y Tecnología](https://fcuba.net/forums/177-informatica-y-tecnologia.md), started by Miembro 1506 on 2023-03-22T06:16:01.000Z.

## Miembro 1506, [2023-03-22T06:16:01.000Z](https://fcuba.net/threads/9237-python-scripts-repo#post-119654)

> Bueno creo este tema con la intención de que compartamos scripts solamente en Python, no se admiten otros lenguajes, yo recién comencé a estudiar Python, así que voy a empezar con algo muy básico, si pueden comentar el funcionamiento del script mejor.
>
> **WARNING!**
> Cualquier parecido de algunos de los scripts publicados aquí con alguno de Stack Overflow o al de algún tutorial es pura coincidencia.
> Script basado en hechos reales.
>
> Un ¨jueguito¨ básico en el que tienes que adivinar un número entre el 0 y el 10 en 3 intentos.
>
> ```python
> # Made by レッド・ノヴァ(Red Nova)
> import random  # import random module
>
> secret_number = random.randint(0, 10)  # it gets a pseudorandom integer between 0 and 10
> guess_count = 0
> guess_limit = 3
>
> print("Guess the number between 0 to 10")
>
> while guess_count < guess_limit:
>     guess = int(input("Guess: "))
>     guess_count +=1
>     if guess == secret_number:
>         print("You won!")
>         break
> else:
>     print("Sorry, you failed")
> ```
>
> Pd: Sabían que una computadora no puede generar verdaderos números aleatorios?(ahora un ¨tufao¨ ve esto y se va a quedar....[attachment] naahhhh mentira!?, ño! eso no me lo sabia... si ya... Lo que genera este pequeño script es un número pseudoaleatorio, que parece aleatorio pero en verdad no lo es.

## RedCubana, [2023-03-22T11:22:48.000Z](https://fcuba.net/threads/9237-python-scripts-repo#post-119657)

> Suerte en tu nuevo patch de vida. Creo que hoy día es importante saber algún tipo de lenguaje de programación.
>
> [@AURORAbot](https://fcuba.net/members/1715) cuales son los lenguajes de programación mas utilizados en la actualidad?

## Miembro 5111, [2023-03-22T12:00:27.000Z](https://fcuba.net/threads/9237-python-scripts-repo#post-119661)

> > **[RedCubana](https://fcuba.net/posts/119657) wrote:**
> > 
> > Suerte en tu nuevo patch de vida. Creo que hoy día es importante saber algún tipo de lenguaje de programación.
> > 
> > [@AURORAbot](https://fcuba.net/members/1715) cuales son los lenguajes de programación mas utilizados en la actualidad?
>
> Buenos días. Amigo. Se la pusiste dura y en China a la señorita AuroraBost.

## RedCubana, [2023-03-22T14:31:55.000Z](https://fcuba.net/threads/9237-python-scripts-repo#post-119665)

> > **[Miembro 5111](https://fcuba.net/posts/119661) wrote:**
> > Buenos días. Amigo. Se la pusiste dura y en China a la señorita AuroraBost.
>
> Se quedo en banda jajaja. Le hice la pregunta a CahtGPT directamente y aqui la respuesta:
>
> [attachment]

## Lucien, [2023-03-22T14:42:14.000Z](https://fcuba.net/threads/9237-python-scripts-repo#post-119668)

> > **[RedCubana](https://fcuba.net/posts/119657) wrote:**
> > 
> > Suerte en tu nuevo patch de vida. Creo que hoy día es importante saber algún tipo de lenguaje de programación.
> > 
> > [@AURORAbot](https://fcuba.net/members/1715) cuales son los lenguajes de programación mas utilizados en la actualidad?
>
> Todavía no funciona así, hay que comprar un addon aparte para eso, y de hecho aún no sale para el publico. Loco estoy porque lo haga.

## RedCubana, [2023-03-22T17:45:59.000Z](https://fcuba.net/threads/9237-python-scripts-repo#post-119682)

> > **[Lucien](https://fcuba.net/posts/119668) wrote:**
> > Todavía no funciona así, hay que comprar un addon aparte para eso, y de hecho aún no sale para el publico. Loco estoy porque lo haga.
>
> Ok entiendo. Creo que es la mejor función al etiquetar al bot, no solo al citar.

## moist, [2023-03-22T17:50:17.000Z](https://fcuba.net/threads/9237-python-scripts-repo#post-119684)

> Sorprendentemente las scripts que uso las escribi en bash.
>
> Aqui un pedazo de codigo al azar para no sentirme excluido.
>
> ```python
> def loggedmethod(method):
>     """Log a CRUD method and confirm its successful execution"""
>     @wraps(method)
>     def wrapper(self, *args, **kwargs):
>         method_data = inspect.getfullargspec(method)
>         method_type = method.__name__.split("_")[0].upper()
>         # + 1 because of self
>         self.logger.info(
>             "%s %s",
>             method_type,
>             [
>                 f"{method_data.args[index + 1]}={value}"
>                 for index, value in enumerate(args)
>             ],
>         )
>
>         res = method(self, *args, *kwargs)
>
>         self.logger.info("%s --success--", method_type)
>         return res
>
>     return wrapper
> ```

## Miembro 1506, [2023-03-23T12:46:14.000Z](https://fcuba.net/threads/9237-python-scripts-repo#post-119844)

> Voy a hacer un push commit en mi código 🤣
>
> > Fixing crash by wrong input value.
>
> ```python
> # Made by レッド・ノヴァ(Red Nova)
> import random  # import random module
>
> secret_number = random.randint(0, 10)  # it gets a pseudorandom integer between 0 and 10
> guess_count = 0
> guess_limit = 3
>
> print("Guess the number between 0 to 10")
>
> while guess_count < guess_limit:
>     guess_count += 1
>     try:
>         guess = int(input("Guess: "))
>     except ValueError:
>         print("Invalid Value")
>         break
>     if guess == secret_number:
>         print("You won!")
>         break
> else:
>     print("Sorry, you failed!")
> ```

## w1re, [2023-03-23T15:04:42.000Z](https://fcuba.net/threads/9237-python-scripts-repo#post-119858)

> > **[Miembro 1506](https://fcuba.net/posts/119844) wrote:**
> > 
> > Voy a hacer un push commit en mi código 🤣
> > 
> > ```python
> > # Made by レッド・ノヴァ(Red Nova)
> > import random  # import random module
> > 
> > secret_number = random.randint(0, 10)  # it gets a pseudorandom integer between 0 and 10
> > guess_count = 0
> > guess_limit = 3
> > 
> > print("Guess the number between 0 to 10")
> > 
> > while guess_count < guess_limit:
> >     guess_count += 1
> >     try:
> >         guess = int(input("Guess: "))
> >     except ValueError:
> >         print("Invalid Value")
> >         break
> >     if guess == secret_number:
> >         print("You won!")
> >         break
> > else:
> >     print("Sorry, you failed!")
> > ```
>
> Deja mandar un parche:
>
> ```diff
> Fix input handling.
> @@ -10,15 +10,18 @@
>  print("Guess the number between 0 to 10")
>  
>  while guess_count < guess_limit:
> -    guess_count += 1
>      try:
>          guess = int(input("Guess: "))
>      except ValueError:
>          print("Invalid Value")
> -        break
> +        continue
> +    if not (0 <= guess <= 10):
> +        print("Out of range")
> +        continue
>      if guess == secret_number:
>          print("You won!")
>          break
> +    guess_count += 1
>  else:
>      print("Sorry, you failed!")
> ```

## Miembro 1506, [2023-03-23T15:30:35.000Z](https://fcuba.net/threads/9237-python-scripts-repo#post-119864)

> > **[w1re](https://fcuba.net/posts/119858) wrote:**
> > 
> > Deja mandar un parche:
> > 
> > ```diff
> > Fix input handling.
> > @@ -10,15 +10,15 @@
> >  print("Guess the number between 0 to 10")
> >  
> >  while guess_count < guess_limit:
> > -    guess_count += 1
> >      try:
> >          guess = int(input("Guess: "))
> >      except ValueError:
> >          print("Invalid Value")
> > -        break
> > +        continue
> > +    if not (0 <= guess <= 10):
> > +        print("Out of range")
> > +        continue
> >      if guess == secret_number:
> >          print("You won!")
> >          break
> > +    guess_count += 1
> >  else:
> >      print("Sorry, you failed!")
> > ```
>
> Estaba buscando como hacer eso que hiciste para resaltar los cambios, ahora si queda más pro👍

## Miembro 1506, [2023-03-26T15:33:55.000Z](https://fcuba.net/threads/9237-python-scripts-repo#post-120114)

> Aburrido me dio por implementar el script de Python en C++
>
> ```python
> import random  # import random module
>
> secret_number = random.randint(0, 10)  # it gets a pseudorandom integer between 0 and 10
> guess_count = 0
> guess_limit = 3
>
> print("Guess the number between 0 to 10")
>
>
> while guess_count < guess_limit:
>     try:
>         guess = int(input("Guess: "))
>     except ValueError:
>         print("Invalid Value")
>         continue
>     if not (0 <= guess <= 10):
>         print("Out of range")
>         continue
>     if guess == secret_number:
>         print("You won!")
>         break
>     guess_count += 1
> else:
>     print("Sorry, you failed!")
> ```
>
> ```cpp
> #include <iostream>
> #include <time.h>
>
> int main()
> {
>     int secret_number;
>     int guess_count = 0;
>     int guess_limit = 3;
>     int guess;
>
>     /* initialize random seed: */
>     srand(time(NULL));
>
>     /* generate secret number: */
>     secret_number = rand() % 10 + 1;
>
>     std::cout << "Guess the number between 1 to 10" << std::endl;
>
>     while (guess_count < guess_limit)
>     {
>         std::cout << "Guess ";
>
>         try
>         {
>             std::cin >> guess;
>             if (guess == NULL || guess > 10)
>                 throw "Invalid Value";
>         }
>         catch (const char * wrongValue)
>         {
>             std::cout << "Exception: " << wrongValue << std::endl;
>             std::cin.clear(); // reset the fail flags
>             std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //ignore the bad input until line end
>             continue;
>         }
>
>         if (guess == secret_number)
>         {
>             std::cout << "You won!" << std::endl;
>             break;
>         }
>         else
>         {
>             std::cout << "You failed" << std::endl;
>         }
>         guess_count++;
>     }
>     return 0;
> }
> ```

## w1re, [2023-03-26T16:44:51.000Z](https://fcuba.net/threads/9237-python-scripts-repo#post-120117)

> > **[Miembro 1506](https://fcuba.net/posts/119864) wrote:**
> > Estaba buscando como hacer eso que hiciste para resaltar los cambios, ahora si queda más pro👍
>
> ```bash
> diff -u FILE1 FILE2
> ```
>
> Para ponerlo aquí selecciona "Diff" en la lista de lenguajes.
>
> Espero que no hayas aplicado el parche a mano.

## w1re, [2023-03-26T18:26:48.000Z](https://fcuba.net/threads/9237-python-scripts-repo#post-120120)

> > **[Miembro 1506](https://fcuba.net/posts/120114) wrote:**
> > 
> > ```cpp
> > /* initialize random seed: */
> > srand(time(NULL));
> > ```
>
> Aquí vale porque es un jueguito, pero no lo uses para cosas serias.
>
> > **[Miembro 1506](https://fcuba.net/posts/120114) wrote:**
> > 
> > ```cpp
> > if (guess == NULL || guess > 10)
> >     throw "Invalid Value";
> > ```
>
> Los `int` no pueden ser `NULL` (bueno, en algunos compiladores `NULL` se expande como `0`), aquí las variables no contienen referencias a objetos estilo Python.
> Tampoco deberías usar excepciones como control de flujo.
>
> [spoiler]

## ßȴƱƸƤƦłŊҪξ, [2023-03-26T18:52:44.000Z](https://fcuba.net/threads/9237-python-scripts-repo#post-120121)

> ```
> import random
>
> numero_seleccionado = random.randint(1, 100)
>
> while True:
>     numero_usuario = int(input("Adivina el número seleccionado: "))
>     
>     if numero_usuario > numero_seleccionado:
>         print("Estás muy alto.")
>     elif numero_usuario < numero_seleccionado:
>         print("Estás muy bajo.")
>     else:
>         print("¡Felicidades! Adivinaste el número seleccionado.")
>         break
> ```

## Miembro 1506, [2023-03-26T18:53:31.000Z](https://fcuba.net/threads/9237-python-scripts-repo#post-120122)

> > **[w1re](https://fcuba.net/posts/120120) wrote:**
> > 
> > Aquí vale porque es un jueguito, pero no lo uses para cosas serias.
> > 
> > Los `int` no pueden ser `NULL` (bueno, en algunos compiladores `NULL` se expande como `0`), aquí las variables no contienen referencias a objetos estilo Python.
> > Tampoco deberías usar excepciones como control de flujo.
> > 
> > [spoiler]
>
> Ando con Visual Studio, improvisé un poco la verdad, but if it works, don´t touch it. Son las reglas amigo.
> [attachment][attachment]
