Python:有沒有辦法使用一定數(shù)量的輸入?

我有一個簡單的pythonwebhook sender for Discord,有3個url輸入。我想弄清楚如何使on選項使用1、2或所有3個輸入。有可能嗎?我不是最有經(jīng)驗的人,所以請回答一些細節(jié)。

from discord_webhook import DiscordWebhook

print('paste webhook 1')
url1 = input()

print('paste webhook 2')
url2 = input()

print('paste webhook 3')
url3 = input()

print('what do you want them to say?')
content = input()
print('sending...')

while True:
    webhook_urls = [url1, url2, url3]
    webhook = DiscordWebhook(url=webhook_urls, content=content)
    response = webhook.execute()

? 最佳回答:

我假設你一開始會問他們要輸入多少個webhook

from discord_webhook import DiscordWebhook


def ask_for_count():
    webhooks_num = input('How many webhooks would you like to use? (1, 2 or 3) \n')
    # Firstly, you don't need a seperate print statement to ask for input
    # it can be in the input function and if you need the answer in a new line,
    # use the escape character /n which creates a new line after execution.
    return webhooks_num


def get_webhooks():
    if count == '1':
        url1 = input('paste webhook 1 \n')
        webhook_urls.append(url1)
        return # The return ends function as soon as the urls are added to the list.

    elif count == '2':
        url1 = input('paste webhook 1 \n')
        url2 = input('paste webhook 2 \n')
        webhook_urls.append(url1)
        webhook_urls.append(url2)
        return

    elif count == '3':
        url1 = input('paste webhook 1 \n')
        url2 = input('paste webhook 2 \n')
        url3 = input('paste webhook 3 \n')
        webhook_urls.append(url1)
        webhook_urls.append(url2)
        webhook_urls.append(url3)
        return

    else:
        print('Please enter a valid choice.')


def get_content():
    answer = input('what do you want them to say? \n')
    print('sending...')
    return answer


webhook_urls = []
# List is intentionally outside of the function,
# so that you don't create an empty list everytime the function is called.

# Now you call the functions defined above to execute in order.
count = ask_for_count()
get_webhooks()
content = get_content()


while True:
    webhook = DiscordWebhook(url=webhook_urls, content=content)
    response = webhook.execute()

因此,基本上,只要程序運行,用戶就會被要求提供所需的webhooks的數(shù)量,然后根據(jù)輸入(共3個),他們會被要求提供webhooks,這些webhooks會被添加到之前啟動的webhook_urls列表中。

之后,用戶被要求提供內(nèi)容,while循環(huán)啟動,使用函數(shù)輸出和先前啟動的列表正常執(zhí)行代碼;webhook_urls。

希望我能幫上忙。

主站蜘蛛池模板: 亚洲高清日韩精品第一区| 日本无卡码一区二区三区| 无码精品人妻一区二区三区人妻斩| 射精专区一区二区朝鲜| 国产一区二区三区播放心情潘金莲| 亚洲国产精品一区二区九九| 日本在线视频一区二区| 高清一区二区三区日本久| 国产成人高清精品一区二区三区 | 成人免费一区二区三区在线观看| 中文字幕精品亚洲无线码一区| 国产一区二区在线观看麻豆| 日韩最新视频一区二区三| 久久人妻内射无码一区三区 | 日韩高清一区二区| 无码中文字幕乱码一区| 色噜噜狠狠一区二区三区| 午夜天堂一区人妻| 日韩电影一区二区| 久久国产精品亚洲一区二区| 精品久久一区二区三区| 国产一区二区精品| 亚洲av福利无码无一区二区| 日韩精品无码免费一区二区三区| 人妻体内射精一区二区三区| 国产精品伦一区二区三级视频| 亚洲欧洲∨国产一区二区三区| 精品久久一区二区| 精品亚洲AV无码一区二区三区| 亚洲一区中文字幕在线观看| 亚洲视频一区二区三区| 男插女高潮一区二区| 亚洲av无一区二区三区| 精品不卡一区中文字幕| 成人区精品一区二区不卡| 亚洲一区二区在线免费观看| 亚洲一区精品视频在线| 无码喷水一区二区浪潮AV| 狠狠爱无码一区二区三区| 久久久久人妻一区精品| 熟妇人妻AV无码一区二区三区|