小编Moh*_*d H的帖子

减少退货单的数量

以下代码返回人员的BMI风险 - ,.它工作得很好.但是,我想知道是否有其他方法可以解决它而不使用太多的返回语句.

有没有其他方法,Pythonic或逻辑上让它更短?

def bmi_risk(bmi, age):
    ''' function returning bmi's risk on human '''
    if bmi < 22 and age < 45:
        return "Low"
    if bmi < 22 and age >= 45:
        return "Medium"
    if bmi >= 22 and age < 45:
        return "Medium"
    if bmi >= 22 and age >= 45:
        return "High"
Run Code Online (Sandbox Code Playgroud)

boolean-logic boolean python-3.x

3
推荐指数
1
解决办法
425
查看次数

计算数组中出现的字母数

我想要一个计算数组中字母出现次数的代码.我已经查看了各种准确的代码,但它们都使用字符串.我的问题是严格使用数组.我创建了一个代码,但它返回:: 0 : 1 : 2 : 3 : 4 : 5 : 6 : 7 : ...

一个正确的例子: 输入:

The quick brown fox jumps over the lazy dog.
Run Code Online (Sandbox Code Playgroud)

输出:

A: 1
B: 1
C: 1
D: 1
E: 3
F: 1 ...
Run Code Online (Sandbox Code Playgroud)

以下是我的代码:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main(void)
{
    int i = 0;
    int c;
    char counts[26] = {0};  

    c = getchar();              


    while (c != EOF && i < 26) { …
Run Code Online (Sandbox Code Playgroud)

c arrays

3
推荐指数
1
解决办法
138
查看次数

如果序列出现在列表中,则返回True

我需要编写一个函数,该函数接受一个int列表,nums如果序列1, 2, 3, ..出现在列表中的某个地方,则返回True 。

我的方法:

def list123(nums):
    num = ""
    for i in nums:
        num += i
    if "1,2,3" in num:
        return True
    else:
        return False
Run Code Online (Sandbox Code Playgroud)

它无法正常工作,表明: builtins.TypeError: Can't convert 'int' object to str implicitly

我还想知道是否有更简单的方法,而不是像我一样将列表转换为字符串。

boolean list sequence python-3.x

2
推荐指数
1
解决办法
4349
查看次数

标签 统计

boolean ×2

python-3.x ×2

arrays ×1

boolean-logic ×1

c ×1

list ×1

sequence ×1