Я хочу получить входные данные со страницы HTML и поместить их в переменную Python. Проблема в том, что я не знаю, как это сделать. Я почти закончил программу на Python, и она работает потрясающе, я просто хочу, чтобы она выглядела лучше на веб-странице, но понятия не имею, как это сделать.
Вот код Python:
import time
import random
# Welcome message
print("Welcome to the ultimate username generator!")
time.sleep(0.5)
# Collecting user information
name = input("What is your name? ")
time.sleep(0.25)
print("Amazing!")
time.sleep(0.5)
age = input("How old are you? ")
time.sleep(0.25)
print("Amazing!")
time.sleep(0.5)
hobby = input("What is your favorite hobby? ")
time.sleep(0.5)
extra_info = input("Do you want to add extra information? Y or N: ").strip().upper()
single_word = ""
number = ""
favorite_color = ""
# Function to collect extra information
def get_extra_info():
global single_word, number, favorite_color
single_word = input("Please provide a single word (no spaces): ")
while ' ' in single_word or len(single_word) == 0:
print("Invalid input. Please enter a single word without spaces.")
single_word = input("Please provide a single word (no spaces): ")
time.sleep(0.5)
number = input("Enter a number (up to 3 digits): ")
while not number.isdigit() or int(number) < 0 or int(number) > 999:
print("Invalid input. Please enter a number between 0 and 999.")
number = input("Enter a number (up to 3 digits): ")
time.sleep(0.5)
def color():
color_list = ["red", "blue", "green", "yellow", "orange", "purple", "pink", "brown", "black", "white", "Red", "Blue", "Green", "Yellow", "Orange", "Purple", "Pink", "Brown", "Black", "White"]
favorite_color = input("What is your favorite color? ")
if favorite_color not in color_list:
print("Invalid input. Please enter a valid color.")
color() # Recursively call the function again
else:
pass
color()
# Collect extra information if requested
if extra_info == "Y":
get_extra_info()
elif extra_info == "N":
pass
else:
print("Invalid input, moving on.")
pass
# Function to generate the username
def gen():
order = random.sample([1, 2, 3, 4, 5, 6], 6) # Changed the range to match available parts
# Map the orders to the corresponding input
parts = {
1: age,
2: name,
3: hobby,
4: single_word,
5: number,
6: favorite_color
}
# Build the final username using the selected parts
final_user = ''.join(parts[order[i]] for i in range(6))
print("Your final username is: " + final_user)
time.sleep(0.5)
# Initial username generation
gen()
# Loop for regenerating username
while True:
redo = input("Would you like to regenerate that username? Type Y or N: ").strip().upper()
if redo == "Y":
gen()
elif redo == "N":
print("Thank you for using the username generator! Goodbye!")
break
else:
print("Invalid input. Please type Y or N.")
Я попробовал py-script и посмотрел несколько видео, но нашел только два, и оба они были от каких-то индийских парней, которых я вообще не мог понять. Я хочу, чтобы вы нажали кнопку «Отправить» после ввода необходимых параметров, таких как имя, возраст, хобби, а затем возникает вопрос, хотите ли вы добавить дополнительные параметры. Дополнительные параметры представляют собой одно слово, трехзначное число и цвет. Sidenote, какие есть хорошие средства форматирования?
Я хочу получить входные данные со страницы HTML и поместить их в переменную Python. Проблема в том, что я не знаю, как это сделать. Я почти закончил программу на Python, и она работает потрясающе, я просто хочу, чтобы она выглядела лучше на веб-странице, но понятия не имею, как это сделать. Вот код Python: [code]
import time import random
# Welcome message print("Welcome to the ultimate username generator!")
time.sleep(0.5)
# Collecting user information name = input("What is your name? ") time.sleep(0.25) print("Amazing!") time.sleep(0.5)
age = input("How old are you? ") time.sleep(0.25)
print("Amazing!") time.sleep(0.5)
hobby = input("What is your favorite hobby? ") time.sleep(0.5)
extra_info = input("Do you want to add extra information? Y or N: ").strip().upper()
single_word = "" number = "" favorite_color = ""
# Function to collect extra information def get_extra_info(): global single_word, number, favorite_color
single_word = input("Please provide a single word (no spaces): ") while ' ' in single_word or len(single_word) == 0: print("Invalid input. Please enter a single word without spaces.") single_word = input("Please provide a single word (no spaces): ")
time.sleep(0.5)
number = input("Enter a number (up to 3 digits): ") while not number.isdigit() or int(number) < 0 or int(number) > 999: print("Invalid input. Please enter a number between 0 and 999.") number = input("Enter a number (up to 3 digits): ")
if favorite_color not in color_list: print("Invalid input. Please enter a valid color.") color() # Recursively call the function again else: pass color()
# Collect extra information if requested if extra_info == "Y": get_extra_info() elif extra_info == "N": pass else: print("Invalid input, moving on.") pass
# Function to generate the username def gen(): order = random.sample([1, 2, 3, 4, 5, 6], 6) # Changed the range to match available parts
# Map the orders to the corresponding input parts = { 1: age, 2: name, 3: hobby, 4: single_word, 5: number, 6: favorite_color }
# Build the final username using the selected parts final_user = ''.join(parts[order[i]] for i in range(6))
print("Your final username is: " + final_user) time.sleep(0.5)
# Initial username generation gen()
# Loop for regenerating username while True: redo = input("Would you like to regenerate that username? Type Y or N: ").strip().upper() if redo == "Y": gen() elif redo == "N": print("Thank you for using the username generator! Goodbye!") break else: print("Invalid input. Please type Y or N.")
[/code] Я попробовал py-script и посмотрел несколько видео, но нашел только два, и оба они были от каких-то индийских парней, которых я вообще не мог понять. Я хочу, чтобы вы нажали кнопку «Отправить» после ввода необходимых параметров, таких как имя, возраст, хобби, а затем возникает вопрос, хотите ли вы добавить дополнительные параметры. Дополнительные параметры представляют собой одно слово, трехзначное число и цвет. Sidenote, какие есть хорошие средства форматирования?
У меня есть код, который я написал для простого кодирования и декодирования паролей, но мне нужно поделиться этими модулями с друзьями и семьей/ packages легко, как лучше всего это сделать.
Мой код:
import cryptocode
choice = input( What do you...
I have an nxd numpy array of zeros. For every row in this array, I am tasked with converting a specified column to be a 1. To this end, I have been given a list of size n such that the ith value of this list is the index to be turned into a 1....