Table of Contents
回复内容:
Home Backend Development PHP Tutorial javascript - 如何Python双阶乘

javascript - 如何Python双阶乘

Jun 06, 2016 pm 08:24 PM
javascript php python

5! = 5*4*3*2*1 = 120;
print reduce(lambda x,y:x*y,range(1,6))#120
5!! = 5*3*1 = 15;
//这个怎么处理?
Copy after login
Copy after login

回复内容:

5! = 5*4*3*2*1 = 120;
print reduce(lambda x,y:x*y,range(1,6))#120
5!! = 5*3*1 = 15;
//这个怎么处理?
Copy after login
Copy after login

import operator
reduce(operator.mul,range(5,0,-2))
Copy after login

或者 你如你坚持自己写乘法,

reduce(lambda x,y:x*y,range(5,0,-2))
Copy after login

另外 如果你不想import

reduce(int.__mul__,range(5,0,-2))
Copy after login

不知道双阶乘的意思 不过你看这个能用吗

reduce(lambda x,y:x*y,range(1,6, 2))
Copy after login

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How to download deepseek Xiaomi How to download deepseek Xiaomi Feb 19, 2025 pm 05:27 PM

How to download deepseek Xiaomi

How do you ask him deepseek How do you ask him deepseek Feb 19, 2025 pm 04:42 PM

How do you ask him deepseek

How to search deepseek How to search deepseek Feb 19, 2025 pm 05:18 PM

How to search deepseek

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

How to program deepseek How to program deepseek Feb 19, 2025 pm 05:36 PM

How to program deepseek

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

PHP Program to Count Vowels in a String

How to use deepseek to settle accounts How to use deepseek to settle accounts Feb 19, 2025 pm 04:36 PM

How to use deepseek to settle accounts

See all articles