小编hak*_*121的帖子

Python-如何确定我的系统可以处理的最大/最小int/long/float /复数

规格: Python 3.3.1

我试图做的是: "使用Python,确定系统可以处理的最大和最小的整数,长整数,浮点数和复数."

我做了什么:我经历了Python的数学模块和所有与数学和数字相关的内置函数,但是找不到这样做的方法.我也尝试了类似的东西,max(range(0,))但它返回ValueError: max() arg is an empty sequence错误.

问题:如何确定我的系统可以使用Python处理的最大/最小int/long/float /复数?作为一个初学者,我知道我一定错过了什么,但我尝试过并且无法弄明白.我感谢您的帮助!

python math max min python-3.x

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

执行函数后,Python脚本会返回意外的"无"

规格:Ubuntu 13.04 Python 3.3.1

背景:Python初学者; 搜索了这个问题但我找到的答案更多的是"什么"而不是"为什么";

我打算做什么:创建一个功能,从用户输入测试分数输入,并根据年级比例/曲线输出字母等级; 这是代码:

score = input("Please enter test score: ")
score = int(score)

def letter_grade(score):
    if 90 <= score <= 100:
        print ("A")
    elif 80 <= score <= 89:
        print ("B")
    elif 70 <= score <= 79:
        print("C")
    elif 60 <= score <= 69:
        print("D")
    elif score < 60:
        print("F")

print (letter_grade(score))
Run Code Online (Sandbox Code Playgroud)

这在执行时返回: None (letter_grade(score) print (letter_grade(score))

"无"并非意图.而且我发现,如果我使用None而不是None,则"无"不再出现.

我能找到的最接近的答案说"像python中的函数返回None,除非明确指示不这样做".但我确实在最后一行调用了一个函数,所以我在这里有点困惑.

所以我想我的问题是:是什么导致了"无"的消失?我确信这是非常基本的东西,但我无法找到解释"幕后"机制的任何答案.所以,如果有人能对此有所了解,我将不胜感激.谢谢!

python printing syntax python-3.x nonetype

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

如何在Python中手动排序数字列表?

规格:Ubuntu 13.04,Python 3.3.1

背景:Python的初学者,遇到了这种"手动排序"问题.

我被要求做的是:"让用户输入3个数值并将它们存储在3个不同的变量中.不使用列表或排序算法,手动将这3个数字从最小到最大排序."

我能想到的是:

number = input("Please enter 3 numbers: ")
number = list(number)

a = int(number[0])
b = int(number[1])
c = int(number[2])

new_l = []

if a > b and a > c:
    new_l.append(a)
    if b > c:
        new_l.append(b)
        new_l.append(c)
    else:
        new_l.append(c)
        new_l.append(b)
    print(new_l)

if b > a and b > c:
    new_l.append(b)
    if a > c:
        new_l.append(a)
        new_l.append(c)
    else:
        new_l.append(c)
        new_l.append(a)
    print(new_l)

if c > a and c > b:
    new_l.append(c)
    if a > b:
        new_l.append(a) …
Run Code Online (Sandbox Code Playgroud)

python sorting list manual python-3.x

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

Python-无法将列表转换为字符串

我想做什么:

获取一个字符串并附加该字符串的向后副本,形成回文

我想出了什么:

# take an input string
a = input('Please enter a string: ')
a = list(a)

# read the string backwards
b = list(reversed(a))

# append the backward-ordered string to the original string, and print this new string
c = a + b
c = str(c)

print(c)
Run Code Online (Sandbox Code Playgroud)

问题:当运行时,该脚本接受一个字符串,例如“test”,并返回['t', 'e', 's', 't', 't', 's', 'e', 't'];我对这个结果感到困惑,因为我将和c串联的结果显式转换为字符串。( ) 我知道我一定错过了一些基本的东西,但我无法弄清楚是什么。有人可以解释一下吗?谢谢你!abc = str(c)

有人愿意详细说明为什么我的c = str(c)不起作用吗?谢谢!

python string list type-conversion python-3.x

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

标签 统计

python ×4

python-3.x ×4

list ×2

manual ×1

math ×1

max ×1

min ×1

nonetype ×1

printing ×1

sorting ×1

string ×1

syntax ×1

type-conversion ×1