E4 – Python programmingGeoinformatics: Geol 4123/6123

In all of the following questions assume arcpy is imported!

  1. Assuming arcpy is imported, print whether or not (Boolean yes or no) the streams.shp dataset exists in your C:/Data folderby calling the exists() function
  1. printarcpy.Exists. C:/Data/streams.shp”
  2. print arcpy.Exists (“C:/Data/streams.shp”)
  3. print arcpy.Exists = C:/Data/streams.shp”
  4. print arcbpy.Exists (C:/Data/streams.shp”) = 1
  1. Retrieve messages through the GetMessages function and print them:
  1. print arcpy.GetMessages
  2. Print arcpy.getMessages
  3. Print arcpy = GetMessages
  4. print arcpy.GetMessages()
  1. Assign the number of messages to the count variable from the GetMessageCount function
  1. Count = GetMessageCount
  2. count.GetMessageCount()
  3. count = arcpy.GetMessageCount()
  4. Count = Arcpy.GetMessageCount
  1. Describe the streams.shp shape file and store it in the desc variable
  1. desc.arcpy.Describe (“C:/Data/streams.shp”)
  2. desc. arcpy.Describe. “C:/Data/streams.shp”
  3. desc = arcpy.Describe (“C:/Data/streams.shp”)
  4. desc.arcpy.Describe = “C:/Data/streams.shp”
  1. Run the Clip tool if the shape type is polygon
  1. if type == “polygon”:

arcpy.Clip_analysis (infc, clipfc, outfc)

  1. if type = “polygon”:

arcpy.Clip_analysis (infc, clipfc, outfc)

  1. If type == “polygon”:

arcpy.Clip_analysis = (infc, clipfc, outfc)

  1. if type = “polygon”:

arcpy.Clip_analysis.(infc, clipfc, outfc)

  1. Get the list of feature classes and assign it to the fcList variable
  2. fcList = arcpy.ListFeatureClasses ()
  3. fcList == arcpy.ListFeatureClasses ()
  4. fcList = arcpy.ListFeatureClasses
  5. fcList = arcpy (ListFeatureClasses)
  1. Loop through the list of fields and print the field name followed by a blank and the string casted field length
  1. for field in fieldList

print field.name. + “ “ + str (field.length)

  1. for field fieldList:

print field.name. = + “ “ + str (field.length)

  1. for field in fieldList

print field.name. + “ “ + “strfield.length”

  1. for field in fieldList:

print field.name. + “ “ + str (field.length)

  1. Print the length of the feature classes
  1. print fcs = len (arcpy.ListFeatureClasses ())
  2. print len (fcs = arcpy.ListFeatureClasses ())
  3. print len (fcs == arcpy.ListFeatureClasses ())
  4. print len (fcs.arcpy.ListFeatureClasses ())
  1. Use a for loop to iterate over the rows in a table, and print the fourth row
  1. for row in cursor

Print row[3]

  1. for row in cursor:

print row[5]

  1. for row in cursor:

print row[3]

  1. for row in cursor:

print row(4)

  1. Insert five rows in a table using a loop. Assume x = 1
  1. while x<=5:

cursor.insertRow (“New Street”)

  1. While x<=5

cursor.insertRow (“New Street”)

  1. while x=5:

cursor.insertRow (“New Street”)

  1. While x<=5:

cursor.insertRow = “New Street”

  1. Loop through a table and delete the first row if its value is “Main ST”.
  1. for row in cursor

If row [0] == “Main ST”:

cursor.deleteRow ()

  1. for row in cursor:

if row [0] = “Main ST”:

cursor.deleteRow ()

  1. for row in cursor:

if row [0] == “Main ST”

cursor (deleteRow ())

  1. for row in cursor:

if row [0] == “Main ST”:

cursor.deleteRow ()

  1. Open the Sample.txt file and assign it to the variable f
  1. f == open (“C:/Data/Sample.txt”)
  2. f = open (“C:/Data/Sample.txt”)
  3. f = open.C:/Data/Sample.txt
  4. f = open (C:/Data/Sample.txt)
  1. Assign a point feature to the point variable
  1. point == arcpy.Point (x, y)
  2. point = arcpy.Point [x, y]
  3. point = arcpy.Point (x, y)
  4. point = arcpy (Point) (x, y)
  1. Assign a point geometry to a variable called pointGeometry. Assume point is a variable to a point object
  1. pointGeometry = arcpy.pointgeometry (point)
  2. pointGeometry = arcpy[PointGeometry (point)]
  3. pointGeometry == arcpy.PointGeometry (point)
  4. pointGeometry = arcpy.PointGeometry (point)
  1. Open a map document and assign it to a variable
  1. mapDoc = arcpy.mapping.MapDocument (C:/Data/GeoMap.mxd)
  2. mapDoc = arcpy.mapping.MapDocument (“C:/Data/GeoMap.mxd”)
  3. mapDoc == arcpy.mapping.MapDocument (“C:/Data/GeoMap.mxd”)
  4. mapDoc = arcpy.mapping(MapDocument (“C:/Data/GeoMap.mxd”))
  1. Assign a layer file to the lyr variable
  1. lyr = arcpy.mapping.Layer (“C:/Data/road.lyr”)
  2. lyr = arcpy.mapping.Layer “C:/Data/road.lyr”
  3. lyr = arcpy.mapping.Layer (C:/Data/road.lyr)
  4. lyr = arcpy.mapping(Layer (“C:/Data/road.lyr”))
  1. Print the layer name in a loop. Assume lyrList is a variable pointing to a list of layers
  1. for lyr in lyrList

print lyr.name

  1. for lyr in lyrList:

printlyr(name)

  1. for lyr in lyrList:

print lyr.name

  1. for lyr in lyrList

print (lyr =name)

  1. Turn on the labels for the layer
  1. lyr.showLabels == True
  2. lyr= showLabels (True)
  3. lyr.ShowLabels == True:
  4. lyr.showLabels = True
  1. If layer name is School
  1. if lyr.name = “School”:
  2. if lyr.name == “School”:
  3. if lyr.name = “School”
  4. if lyr.name( “School”):
  1. Print the first message
  1. arcpy.GetMessage = 0
  2. arcpy.GetMessage [0]
  3. arcpy.GetMessage ==0
  4. arcpy.GetMessage (0)
  1. Write code to ask the user to enter his/her last name:
  1. lastName == input("Please enter your last name >")
  2. lastName = input ("Please enter your last name >")
  3. lastName.input = ("Please enter your last name >")
  4. lastName = input (Please enter your last name >)
  1. Call a function called pow () by passing a number a to be powered with a second number b. Assign the result to a variable called result.
  1. Import.math> result== math.Pow (3, 2) > print (result)
  2. > Import math> result= math(pow (3, 2)) > print (result)
  3. > Import math> result= math.pow (3, 2) > print (result)
  4. > Import math> result== math(pow (3, 2)) > print (result)
  1. Python code to print an empty,vertical rectangle.
  1. > rec = (9*'_' + "\n|\t|\n\n|\t|\n\n|\t|\n" _ 9*'_')> print rec
  2. > rec = (9*'_' "\n|\t|\n\n|\t|\n\n|\t|\n" + 9*'_')> print rec
  3. > rec = (9*'_' + "\n|\t|\n\n|\t|\n\n|\t|\n" + 9*)> print rec
  4. > rec = (9*'_' + "\n|\t|\n\n|\t|\n\n|\t|\n" + 9*'_')> print rec
  1. Write Mississippi
  1. > print ("Mi"+2*'s'+'i'+2*'s'+'i'+2*'p'+'i')
  2. > print ('Mi' + 2*(2*'s')+'i'+2*'p'+'i')
  3. a and b
  4. > print (Mi + 2*(2*'s')+'i'+2*'p'+'i')
  1. Replace Bush with Obama
  1. > print (bush.replace ('Bu', 'Oba') + bush.replace ('sh', 'ma'))
  2. > print (bush.replace ('Bush', 'Oba') + bush.replace ('sh', 'ma'))
  3. > print (bush.replace ('Bush', 'Oba') + bush.replace ('Bush', 'ma'))
  4. > print (bush.replace ('Bush', 'Oba'),bush.replace ('Bush', 'ma'))
  1. Reverse the letter of the symmetric words:kayak, level, and radar, and print the reversed version:
  1. > words = ('k','a','y','a','k','l','e','v','e','l','r','a','d','a','r') > words.reverse() > print words
  2. > words = “'k','a','y','a','k','l','e','v','e','l','r','a','d','a','r'” >words.reverse() > print words
  3. > words = ['k','a','y','a','k','l','e','v','e','l','r','a','d','a','r'] > words.reverse() > print words
  4. > words == 'k','a','y','a','k','l','e','v','e','l','r','a','d','a','r' > words.reverse() > print words
  1. Define a tuple for the solar calendar seasons (Spring is first season) and print” Fall is season 3
  1. > (Spring, Summer, Fall, Winter) = (1, 2, 3, 4) > print ("Fall is season " + Fall)
  2. > (Spring, Summer, Fall, Winter) = (1, 2, 3, 4) > print "Fall is season " + Fall
  3. > (Spring, Summer, Fall, Winter) = [1, 2, 3, 4] > print ("Fall is season ") + Fall
  4. > (Spring, Summer, Fall, Winter) = (1, 2, 3, 4) > print ("Fall is season "), Fall
  1. Define a dictionary for the Geoinformatics and GIS courses, and print the dictionary into a set.
  1. coursePrefix = {'Geoinformatics', 'Geol 4123/6123', 'GIS', 'GEOG 4532/6532'}

> print copy.coursePrefix

  1. coursePrefix = {'Geoinformatics', 'Geol 4123/6123', 'GIS', 'GEOG 4532/6532'}

> print coursePrefix.copy ()

  1. coursePrefix = ('Geoinformatics', 'Geol 4123/6123', 'GIS', 'GEOG 4532/6532')

> print coursePrefix.copy ()

  1. coursePrefix = {'Geoinformatics', 'Geol 4123/6123' + 'GIS', 'GEOG 4532/6532'}

> print coursePrefix.copy {}

  1. When would the second print in the following code write?

year = 1990

> while year<2000 :

... print ("The year is in the 20th Century: "), year

... year +=2

... else :

... print ("The year is in the 20th Century: "), year

... year +=2

  1. When year is 2006
  2. When year is 2010
  3. When year is 2000
  4. When year is 2002
  1. Which lines of code finds the numbers that are divisible by 6?
  1. > numbers = [7, 15, 23, 36, 6]
    > for i in numbers: if (i%6=0) :print ("The number is divisible by 6"), i
  2. > numbers = [7, 15, 23, 36, 6]
    > for i in numbers: if (i%6==0) : print ("The number is divisible by 6") + i
  3. > numbers = [7, 15, 23, 36, 6]
    > for i in numbers: if (i%6==0) : print ("The number is divisible by 6"), i
  4. > numbers = [7, 15, 23, 36, 6]
    > for x in numbers: if (i%6==0) : print ("The number is divisible by 6"), i