(Python)如果我有一个点(0,0),我怎么能用给定的数字改变那个点的x值

时间:2013-04-01 23:46:02

标签: python

我有一个点(0,0),我想用该用户指定的值增加该点的x坐标。

def change_coordinates():
    origin = (0,0)
    x = input("By how much do you want to increase the x value?")
    # here I need a code that would change origin from (0,0) to (0+x,0)

2 个答案:

答案 0 :(得分:1)

如果您使用python 2.7.3或更低版本:

origin = (origin[0] + x, origin[1])

如果您的python版本大于3:

origin = (origin[0] + int(x), origin[1])

答案 1 :(得分:0)

position = (1, 2)
x, y = position
position = (x + 3, y)
# now position is (4, 2)