[PYTHON] Programas hechos por mi (aprendiendo)


Code-Language-Colors-Example.jpg


Estos son algunos de los programas por así decirlo más "avanzados" que he hecho (estoy empezando ahora, así que avanzado significa cosas muy básicas)

Este trata en hacer 10 sumas en el menos tiempo posible, te va poniendo las operaciones hasta hacer 10, al terminar, te dice el tiempo que has tardado en hacerlas:
Código:
import time
import random

input("Presiona ENTER para empezar: ")

tiempo = time.time()


for x in range(10):
    value = random.randint(1,10)
    value1 = random.randint(1,10)
    print(value, "+", value1)
    input("= ")
    print("")

tiempo1 = time.time()

total = round(tiempo1 - tiempo)

print("Has hecho 10 operaciones en", total, "segundos.")

input("Presiona ENTER para terminar: ")

Este es una calculadora que a mi parecer, es el que más me ha gustado de hacer, gracias a la ayuda de algunos Noders.

(Es una calculadora para operaciones de 2 números, osea, 22 + 30, 51235 + 4912849, 1 / 1, 412 * 40, seguramente lo modifique y haga que se pueda elegir de cuantos números quieres hacer las operaciones)


Código:
from time import sleep

print("CALCULADORA by Dark")
print("")

for x in range(6,38):

    r1 = int(input("Primer número: "))

    print("")

    operacion = str(input("| + | - | / | * |: "))

    print("")

    r2 = int(input("Segundo número: "))

    print("")

    print(r1, operacion, r2, "=")

    print("")

    sleep(1)

    if operacion == "+":
        suma = r1 + r2
        print(">", suma , "<")
        print("")

    elif operacion == "-":
        resta = r1 - r2
        print(">", resta , "<")
        print("")

    elif operacion == "/":
        division = r1 / r2
        print(">", division , "<")
        print("")

    elif operacion == "*":
        multiplicacion = r1 * r2
        print(">", multiplicacion ,"<")
        print("")

    else:
        print("La operación introducida es incorrecta. Por favor introduzca: | + | - | / | * |")

Este lo que hace es generar Steam Keys (son números y letras completamente aleatorias, pero para el que se aburra...) (lo hice con ayuda de @cbrn)
Código:
import random

print("Fake Steam Keys Generator\n")
input("Press ENTER to generate a key")

while True:

    def get_random_string(length):
        # put your letters in the following string
        sample_letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
        result_str1 = ''.join((random.choice(sample_letters) for i in range(length)))
        result_str2 = ''.join((random.choice(sample_letters) for i in range(length)))
        result_str3 = ''.join((random.choice(sample_letters) for i in range(length)))
        print(result_str1+"-"+result_str2+"-"+result_str3)
        input("")

    get_random_string(5)
También podéis usar esta función como comando de Discord con un bot creado por mi en Discord JavaScript, DarkGame >>> ENLACE <<<

Y por último, un minijuego de elegir 2 posibilidades que hice, para aprender sobre bucles y condicionales:
Código:
from time import sleep

print("Some kind of game")
print("")

for x in range(6,23):
    print("There are 2 doors...")
    sleep(1)
    print("The door 1 is red")
    sleep(2)
    print("The door 2 is blue")
    q1 = input("Which door do you want to open? (1 or 2): ")
    print("Loading...")
    sleep(2)
    print("")
 
    if q1 == "2":
        print("Nice, you opened the door and you found a mystery box")
        break

    if q1 == "1":
        print("Oh god, you opened the door and somebody shot you")
        sleep(1)
        print("GAME OVER!")
        input("Say something to start again the game: ")

for x in range(28,50):
    q2 = input("Do you want to open the mystery box?: ")
    print("Loading...")

    if q2 == "yes":
        sleep(1)
        print("Oh, there is some weird key.")
        print("Take it and let's keep walking...")
        print("")
        sleep(3)
        break

    if q2 == "no":
        print("Well, if I was you I should opened it but, whatever...")
        sleep(2)
        print("Keep walking...")
        sleep(3)
        print("You found a door with a keylock.")
        sleep(2)
        print("You need a key to open it, maybe the mystery box had a key inside it...")
        sleep(2)
        input("Do you want to go back?: ")
        sleep(2)
        print("Well, I don't care if you say yes or not, we go back.")
        print("")

for x in range(52,66):
    print("You found a door with a keylock")
    print("")
    sleep(2)
    print("Maybe you can use the key you found inside the mistery box")
    print("")
    sleep(2)
    print("You opened the door, there is a gun and a banana.")
    print("")
    sleep(2)
    q3 = input("Which one do you want?(gun or banana): ")
    print("Loading...")
    sleep(2)
    print("")

    if q3 == "banana":
        print("Nice!")
        print("You won the game! Enjoy your banana.")
        break

    if q3 == "gun":
        print("You took the gun? Oh, enjoy dying of hungry...")
        sleep(3)
        print("Let's repeat that last quest")
        print("")
        sleep(4)

input("Press ENTER to END the game")