小编Ste*_*nda的帖子

用于字符串修改的Python代码无法正常工作

这段代码应该接受一个字符串输入并输出另一个字符串,它只是输入字符串的修改版本.我不能让它工作.

它应该输出一个字符串,其中每个字母是输入字符串的下一个字母.但是在运行代码时,它只输出相同的输入字符串而不是修改后的字符串.

def str_changer(string):

       string_list = list(string)
       alphabets = 'abcdefghijklmnopqrstuvwxyz'
       positions = []
       for letter in string_list:
         positions.append(alphabets.index(letter))
       for each in positions:
         each = each + 1
       for each in string_list:
         string_list[string_list.index(each)] = 
       alphabets[positions[string_list.index(each)]]

       another = ''.join(string_list)



       return another



    lmao = raw_input('Enter somin\'')
    print str_changer(lmao)
Run Code Online (Sandbox Code Playgroud)

python string python-2.7

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

运算符重载导致错误结果

我有一个 Vector3 类,它的 + 和 * 运算符重载如下:

Vector3& operator+ (Vector3& v1, Vector3& v2)
{
    Vector3 sum = Vector3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
    static Vector3& ref = sum;
    return ref;
}

Vector3& operator* (Vector3& v1, double value)
{
    Vector3 product = Vector3(v1.x * value, v1.y * value, v1.z * value);
    static Vector3& ref = product;
    return ref;
}

Vector3& operator* (double value, Vector3& v1)
{
    Vector3 product = Vector3(v1.x * value, v1.y * value, v1.z * value); …
Run Code Online (Sandbox Code Playgroud)

c++ vector operator-overloading

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

标签 统计

c++ ×1

operator-overloading ×1

python ×1

python-2.7 ×1

string ×1

vector ×1