Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

85
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda