1

入力した座標が特定の領域内にあるかどうかを確認できるコードを作成する必要があります。これまでのところ、私はこれを持っています:

import random
import math
import pylab
import numpy    
pylab.close("all")                                                      #All import statements
x = [(random.randint(-50,50)) for i in range(10)]               #Creating list of x coordinates
y = [(random.randint(-50,50)) for j in range(10)]               #Creating list of y coordinates
array=zip(x,y)                                                          #Creating an array by combining the x and y coordinates
print array             

counter = 0                                 #Start of 1c, resetting counter
for i, j in array:                              #Telling what to inspect
        if 35**2 <= (i**2+j**2) <= 65**2:                   #Conditions for the coordinates to fall within 15 pixels of a circle with radius 50
                counter+= 1                         #If conditions met then add 1 to counter
n=(1.0*counter/7000)*100                            #Calculating percentage of coordinates in the region
print "on average", n, "% of the locations in the array fall in this region"    #Print result, end of part 1c


name = raw_input('type a coordinate location: ')                #Start of 1d, python input result
for i, j in name:
    if i in name in array:   
        if 35**2 <= (i**2+j**2) <= 65**2:
            print "warning, your chosen location falls near the edge of the circle"
    else:
         print "coordinate does not exist"

しかし、現時点では、「name = raw_input('座標位置を入力してください: ')」行を参照して、「アンパックするには複数の値が必要です」というエラー メッセージが表示されます。私は何を間違っていますか?

4

2 に答える 2

0

名前は文字列です。あなたは使用できません

for i, j in name:

最初に値に分割し、タプルを作成する必要があります。

多分このようなもの:

n = (name.split(',')[0],name.split(',')[1]) - 座標が「,」で区切られていると仮定

于 2013-04-10T08:43:42.343 に答える