Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

86
Vistas
specific text in prompt for pythonscript

In JavaScript, you can use prompt("This text is above the field of the prompt.", "This text is in the field of the prompt.") to get a customized window appearing.

In PythonScript you can trigger the prompt by using input(), but input(“Please enter your name”, “Harry Potter”) doesn't work the way JS does.

So how can I trigger such behaviour?

Edit: Screenshot of what I want.

Here is my simple code, although it isn't necessarily relevant for the question:

HTML

<!DOCTYPE html>
<html lang="de">
    <head>
        <title>PyScript</title>
        <link rel="stylesheet"href="https://pyscript.net/alpha/pyscript.css"/>
        <script defer src="https://pyscript.net/alpha/pyscript.js"></script>
    </head>
    <body>
        <py-script src="script.py" />
    </body>
</html>

PYTHON

print("Enter the elements for comparison like this: Element1, Element2, Element3")

elements_list = input().split(", ")

def swap(list, i, j):
    temp = list[i]
    list[i] = list[j]
    list[j] = temp
    
for i in range (len(elements_list)-1):
    for i in range (len(elements_list)-1):
        if input (f"""{elements_list[i]} (type 1) or {elements_list[i+1]} (type 2)?""") == "2":
            swap (elements_list, i, i+1)


print("Your order ", elements_list)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To set a default value of input, use the or operator. If the first value is truthy (evaluates to True with bool(...)), it returns the left side, otherwise, it returns the right side.

An empty string, "", is falsy, so it returns whatever's to the right.

The generic way to do this is:

name = input("What is your name?") or "Alex"
print(f"Your name is {name}")
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda