Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

82
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!