'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)
Solution 1:[1]
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}")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Samathingamajig |
