RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

问题[python]

Martin Hope
Flowerself
Asked: 2025-04-30 18:31:16 +0000 UTC

我不知道错误是什么,按钮不起作用,机器人没有反应

  • 6
import asyncio
from random import randint
from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, filters, CallbackQueryHandler, ContextTypes
from telegram import InlineKeyboardButton, InlineKeyboardMarkup

choices = ["камень", "ножницы", "бумага"]

scissors = InlineKeyboardButton("Ножницы", callback_data="Ножницы")
rock = InlineKeyboardButton("Камень", callback_data="Камень")
paper = InlineKeyboardButton("Бумага", callback_data="Бумага")

rockboard = InlineKeyboardMarkup([
    [scissors, rock],
    [paper]
])

TOKEN = ''


async def start_cmd(update: Update, context: ContextTypes.DEFAULT_TYPE):
    print(update.effective_user.first_name)
    print("Получена команда /game")
    await update.message.reply_text(f'Привет, 🎮\nДавай сыграем в Камень, Ножницы, Бумага! Выбери свой вариант ниже ⬇️"', reply_markup=rockboard)

async def handle_choice(update: Update, context: ContextTypes.DEFAULT_TYPE):
    bot_choice = randint.choice(["Камень", "Ножницы", "Бумага"])
    result = determine_winner(update.message.text, bot_choice)
    await update.message.reply_text(f"Вы выбрали: {update.message.text} Бот выбрал: {bot_choice} Результат: {result}")

def determine_winner(user, bot):
    if user == bot:
        return "Ничья!"
    elif (user == "камень" and bot == "ножницы") or \
            (user == "ножницы" and bot == "бумага") or \
            (user == "бумага" and bot == "камень"):
        return "Ты выиграл!"
    else:
        return "Я выиграл!"

def main():
    application = Application.builder().token(TOKEN).build()
    application.add_handler(CommandHandler("game", start_cmd))
    print("Бот запущен!")
    application.run_polling()

if __name__ == '__main__':
    main()
python
  • 1 个回答
  • 34 Views
Martin Hope
Филипп Шувалов
Asked: 2025-04-29 18:15:51 +0000 UTC

CadQuery python:构建对象的复杂倒角

  • 8

尝试在 CadQuery Python 中对螺栓进行建模:

import cadquery as cq
from math import sqrt, tan, radians

# Параметры модели
head_diameter = 10.0  # Диаметр по вершинам (описанная окружность)
head_height = 5.0     # Высота головки
shaft_diameter = 5.0  # Диаметр стержня
shaft_length = 20.0   # Длина стержня

# Расчетные параметры
R = head_diameter / 2                 # Радиус описанной окружности
r = R * sqrt(3)/2                     # Радиус вписанной окружности
chamfer_size = (R - r) / tan(45)      # Размер фаски для угла 45°

#1. Создаем шестигранную головку
bolt_head = (
    cq.Workplane("XY")
    .polygon(6, 2*R)                  # Создаем шестигранник
    .extrude(head_height)              # Выдавливаем на высоту головки
    .translate((0, 0, -1 * (head_height/2)))
)

bolt_head = bolt_head.edges("Z").chamfer(1)

# 2. Создаем стержень
bolt_shaft = (
    cq.Workplane("XY")
    .circle(shaft_diameter/2)
    .extrude(-shaft_length)
)

# 3. Объединяем компоненты
bolt = bolt_head.union(bolt_shaft)

结果是这样的胡言乱语: 在此处输入图片描述

现在的问题是。如何以 45 度角切割螺栓头的顶角。目标是得到像这样的螺栓头: 在此处输入图片描述

python
  • 2 个回答
  • 49 Views
Martin Hope
Лиза Кригер
Asked: 2025-04-29 14:14:48 +0000 UTC

如何编写不重复最大行数的代码

  • 6

电子表格文件每行包含七个自然数。确定表格行中满足以下条件的最小数字的总和:

  • 一行中有两个数字,每个数字重复两次,另外三个数字不同;

  • 最大行数不重复。

在你的回答中,只写下数字。

f = open("9")
cnt = 0
for s in f:
    a = list(map(int, s.split()))
    povt = [x for x in a if a.count(x) > 1]
    ne_povt = [x for x in a if a.count(x) == 1]
    if (len(ne_povt) == 3 and len(set(povt)) == 2) and max(ne_povt) == 1:
        cnt += 1
print(cnt)
python
  • 2 个回答
  • 103 Views
Martin Hope
geo
Asked: 2025-04-28 18:28:02 +0000 UTC

自定义异常集存储在哪里?

  • 5

为了在类中使用,我需要一组异常,我从 Exceptions 继承并将该组异常存储在模块中(在标题中),我将其构造如下:

class BaseUserError(Exception):
    pass

class AccountError(BaseUserError):
    pass

class DebitError(AccountError):
    pass

class CreitError(AccountError):
    pass

希望将它们移动到用作子类的类中(例如,Account 类、Client 类等等)。这样看来似乎更正确。谁存储在哪里以及为什么存储?

python
  • 1 个回答
  • 35 Views
Martin Hope
t1m013y
Asked: 2025-04-26 20:37:06 +0000 UTC

string.Template 是否安全

  • 5

我正在创建一个 Python 应用程序,它允许我在某些行中使用变量。假设字符串和变量列表都是由用户直接提供的(在这种情况下,安全意味着防止 SSTI 等攻击),那么使用标准库对象string.Template(https://docs.python.org/3/library/string.html#template-strings )是否安全?

换句话说,这样的代码是否安全:

import string

template_str = input("Введите строку: ")
variables = {}
while True:
    name = input("Введите имя переменной (оставить пустым для отмены): ")
    if not name.strip():
        break
    value = input("Введите значение переменной: ")
    name, value = map(lambda s: s.strip(), [name, value])
    if name in variables.keys():
        print("Такая переменная уже существует")
    else:
        variables.update({name: value})

t = string.Template(template_str)
res = t.substitute(variables)
print(res)

注意:问题是如果用户可以控制字符串、变量名和值,使用过程是否安全,string.Template而不是接下来字符串会发生什么。

python
  • 1 个回答
  • 65 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5