Skip to content

Commit 526917d

Browse files
authored
Add files via upload
0 parents  commit 526917d

21 files changed

+2415
-0
lines changed

Diff for: CITIES.SBN

34.2 KB
Binary file not shown.

Diff for: CITIES.SBX

1.57 KB
Binary file not shown.

Diff for: CITIES.SHP

86.2 KB
Binary file not shown.

Diff for: CITIES.SHX

24.7 KB
Binary file not shown.

Diff for: NC2010.txt

+101
Large diffs are not rendered by default.

Diff for: Script - 2.py

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#GEOG 592 Lab 2
2+
#Question 1
3+
# Ask a user to input the radius value for a circle,
4+
# Prompt the user with its area and perimeter values
5+
# (Used try-except for error handling, while loop)
6+
from math import pi
7+
#while(True): keeps the loop running infinitely
8+
while(True):
9+
try:
10+
radius_circle = float(input('The radius of the circle in cm: '))
11+
break #needed to be added to come out of the loop
12+
except ValueError:
13+
print('Invalid Format! Input a number!')
14+
15+
def area_peri_circle():
16+
area_circle = pi*radius_circle**2
17+
perimeter_circle = 2*pi*radius_circle
18+
print('The area of the circle is', format(area_circle, '.2f'), 'cm².','\nThe perimeter of the circle is',format(perimeter_circle, '.2f'), 'cm.')
19+
area_peri_circle()
20+
# function is defined at the beginning and called at the end
21+
22+
23+
#Question 2
24+
#Ask user to input a list of numbers, separated by space,
25+
#Prompt the user with the average, median, sum of the list
26+
#Output a sorted list.
27+
# (Added error handling and while loop)
28+
while(True):
29+
try:
30+
user_input = input('Input a list of numbers separated by space: ')
31+
numbers_list = list(map(float, user_input.split(" ")))
32+
break #needed to be added to come out of the loop
33+
except ValueError:
34+
print('Invalid Format! Try again!')
35+
#Calculating the sum
36+
len = len(numbers_list) # counts the number of numbers in the list
37+
sum = 0
38+
for i in numbers_list:
39+
sum += i # sum = sum + i
40+
print(f'The sum of the numbers in the list: {sum}')
41+
#Calculating the average
42+
print(f'The average of the numbers in the list: {sum/ len}')
43+
#Calculating the median
44+
numbers_list.sort()
45+
if len % 2 == 0:
46+
median1 = numbers_list[len//2]
47+
median2 = numbers_list[(len // 2)-1]
48+
median = (median1 + median2)/2
49+
else:
50+
median = numbers_list[len//2]
51+
print(f'The median of the numbers in the list: {median}')
52+
53+
#Question 3
54+
ncFile = open('NC2010.txt', 'r') #opening a file for the pupose of reading it i.e file 1
55+
allLines = ncFile.readlines()[1:] #skipping the first line(header) and reading all lines in ncFile i.e file 1
56+
file = open('ncpopchg.txt','w') #opening a new fie for the purpose of writing in it i.e file 2
57+
for aLine in allLines: #working with ncFile ('NC2010.txt') first i.e. file 1
58+
aListTokens = aLine.split(',') # the split function performs the split based on the comma
59+
aListTokens[6], aListTokens[8] = float(aListTokens[6]), float(aListTokens[8]) #changing values to float
60+
pop_change = ((aListTokens[8]-aListTokens[6])/aListTokens[8])*100 #calculation
61+
file.write(aListTokens[1]+',') #writing to the created file i.e file 2 ('ncpopochang.txt')
62+
file.write(str(pop_change)+'%'+'\n')
63+
ncFile.close() #closing file 1
64+
file.close() #closing file 2
65+
66+
#Question 4
67+
ncFile2 = open('NC2010.txt', 'r') ##opening a file for the pupose of reading it i.e file 1
68+
allLines2 = ncFile2.readlines()[1:] #skipping the first line(header) of file 1 and reading its content
69+
file2 = open('ncpopchgSorted.txt','w') #opening a new file for the purpose of writing in it i.e file 2
70+
county_list = [] #creating an empty list
71+
for aLine2 in allLines2: #working with file 1
72+
aListTokens2 = aLine2.split(',') # the split function performs the split based on the comma
73+
aListTokens2[6], aListTokens2[8] = float(aListTokens2[6]), float(aListTokens2[8]) #chaning values to float
74+
pop_change2 = ((aListTokens2[8]-aListTokens2[6])/aListTokens2[8])*100 #calculation
75+
county_list.append((aListTokens2[1],pop_change2)) #adding the values of file 1 to the empty list (county_list) using the append function
76+
county_list.sort(key=lambda x:x[1]) #sorting the appended list (county_list)
77+
for list_2 in county_list: #county_list has two columns
78+
alinestring = list_2[0]+','+str(list_2[1])+'%'+'\n' #formatting the two colums of county_list and using it to form 'alinestring' variable
79+
file2.write(alinestring) #writing variable to file 2 (the file that was opening for the purpose of writing into it)
80+
81+
ncFile2.close() #closing file 1
82+
file2.close() # closing file 2
83+
84+
#Question 5
85+
#Part a)calculating the mean center of both list
86+
list1 =[(10,20),(25,8),(34,22),(17,35),(9,1),(31,20),(44,11)] #list 1 of coordinate points
87+
list2 = [(1,21),(19,22),(23,12),(51,26),(78,61),(41,17),(11,21),(81,10),(79,51)] #list 2 of coordinate points
88+
combined_list = list1 + list2 #adding list 1 and list 2 together
89+
def mean_center(tList): #defining the mean center function
90+
middle_point = [0,0] #setting the median point value
91+
n = 0
92+
for p in tList:
93+
middle_point[0] += p[0]
94+
middle_point[1] += p[1]
95+
n+=1
96+
x = middle_point[0]/n
97+
y = middle_point[1]/n
98+
print('%.2f'%x, '%.2f'%y)
99+
mean_center(list1) #mean center of list 1
100+
mean_center(list2) #mean center of list 2
101+
mean_center(combined_list) ##mean center of list 1 and 2
102+
103+
#part b) finding the average distance between a point in list1 and a point in list 2
104+
total_dist = 0
105+
for point1 in list1:
106+
for point2 in list2:
107+
dist = ((point1[0]-point2[0])**2 + (point1[1]-point2[1])**2)**.5 #calculating the distance of the points
108+
total_dist += dist #incrementing the distance calculated above into total_dist (was intially set to 0)
109+
avg_dist = total_dist/(len(list1) * len(list2))
110+
print('The total distance is', '%.2f'%total_dist)
111+
print('The average distance between a point in list 1 and a point in list 2 is', '%.2f'%avg_dist)
112+
113+
#Question 6
114+
city_file = open('cities.txt','r') #opening a text file for the pupose of reading it i.e file 1
115+
location_file = open('locations.txt','r') #opening a text file for the pupose of reading it i.e file 2
116+
all_cities = city_file.readlines()[1:] #reading file 1, excluding the header
117+
all_locations = location_file.readlines()[1:] #reading file 2, excluding the first line, which is the header
118+
location_list = [] #creating an empty list
119+
120+
for aloc in all_locations: #reading file 2
121+
alocArgList = aloc.split(',') #spliting the contents of file 2
122+
location_ID = alocArgList[0] #calling a column
123+
location_x = float(alocArgList[1]) #calling a column and tranforming its values to float
124+
location_y = float(alocArgList[2]) #calling a column and tranforming its values to float
125+
126+
total_distance = 0
127+
for aCity in all_cities: #reading file 1
128+
acityArgList = aCity.split(',') #spliting the contents of file 1
129+
city_name = acityArgList[0] #calling a column
130+
city_x = float(acityArgList[1]) #calling a column and tranforming its values to float
131+
city_y = float(acityArgList[2]) #calling a column and tranforming its values to float
132+
distance_calc = ((city_x-location_x)**2 + (city_y-location_y)**2)**.5 #distance calculation
133+
total_distance += distance_calc #incrementing the distance calculated above into total_distance (was intially set to 0)
134+
total_distance_miles = (total_distance/5280) # Converting feet to miles using 1 mile = 5280 feet
135+
location_list.append((location_ID, total_distance_miles)) #appending two columns into a an empty lise
136+
location_list.sort(key = lambda x:x[1]) #sorting a list
137+
location_list[0][0]
138+
#print(location_list)
139+
print('Best location ID =' , location_list[0][0],'.','Average Distance (miles) from all cities =', '%.2f'%location_list[0][1] )

Diff for: Script -1.py

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Question 1
2+
# Diagnosing if a person is underweight or overweight
3+
# (Used try-except for error handling, if-elif-else statement)
4+
try:
5+
height = float(input('The height of the patient in ft: ')) # in feet
6+
except ValueError:
7+
print('Invalid Input for Height!')
8+
9+
try:
10+
weight = float(input('The weight of the patient in lbs: ')) # in pounds
11+
except ValueError:
12+
print('Invalid Input for Weight!')
13+
14+
try:
15+
sw = (height * 30.48-105)/0.454 #The standard weight of the patient
16+
except ValueError:
17+
print('Invalid Input for Height and/or Weight!')
18+
except NameError:
19+
print('Invalid Input for Height and/or Weight!')
20+
21+
try:
22+
if weight < sw*0.9 and weight > 0 and height > 0:
23+
print('Standard weight =', format(sw, '.3f'), 'This person is underweight!')
24+
elif sw *0.9 <= weight and weight <= sw*1.1 and weight > 0 and height > 0:
25+
print('Standard weight =', format(sw, '.3f'), 'This person has a normal weight')
26+
elif sw * 1.1 < weight and weight <= sw*1.2 and weight > 0 and height > 0:
27+
print('Standard weight =', format(sw, '.3f'), 'This person is overweight!')
28+
elif sw*1.2 < weight and weight <= sw*1.3 and weight > 0 and height > 0:
29+
print('Standard weight =', format(sw, '.3f'), 'This person has Class I Obesity!')
30+
elif sw*1.3< weight and weight <= sw*1.4 and weight > 0 and height > 0:
31+
print('Standard weight =', format(sw, '.3f'), 'This person has Class II Obesity!')
32+
elif sw*1.4< weight and weight > 0 and height > 0:
33+
print('Standard weight =', format(sw, '.3f'), 'This person has Class III Obesity!')
34+
else:
35+
print('Standard weight =', format(sw, '.3f'), ', which is impossible for a person!')
36+
except ValueError:
37+
print('Unable to calculate Standard Weight!')
38+
except NameError:
39+
print('Unable to calculate the Standard Weight!')
40+
#ValueError: The Python ValueError is raised when the wrong value is assigned to an object.
41+
#This can happen if the value is invalid for a given operation, or if the value does not exist
42+
43+
#NameError:NameError occurs when you try to use a variable, function, or module that doesn't exist
44+
#or wasn't used in a valid way. Some of the common mistakes that cause this error are: Using a variable or function name that is yet to be defined.
45+
46+
47+
# What does a negative standard weight mean?
48+
49+
#Question 2
50+
#guessing a number between 1 to 10
51+
# (Used try-except for error handling, if-elif statement, while loop)
52+
import random
53+
tries = 0
54+
number = random.randint(1,100+1) # interger from 1 to 100
55+
56+
#Infinite loop
57+
while(True):
58+
try:
59+
guess = int(input('Guess a number between 1 to 100: '))
60+
while guess != number:
61+
if guess < number:
62+
print('Your guess is smaller than the correct number')
63+
guess = int(input('Guess again: '))
64+
tries = tries + 1
65+
elif guess > number:
66+
print('Your guess is greater than the correct number')
67+
guess = int(input('Guess again: '))
68+
tries = tries + 1
69+
print('Congratulations! You guessed right!', 'It took you,', tries, 'try/tries!')
70+
break
71+
except ValueError:
72+
print('Invalid Input!')
73+
#summary --> if 'guess' is not equal to 'number', it checks for whether it is smaller or greater, counts the number of tries, asks user to guess again
74+
# until the number is found.
75+
76+
# Question 3
77+
# converting dd:mm:ss to decimal degrees
78+
# (Used try-except for error handling, while loop)
79+
while(True):
80+
try:
81+
dms = input('Input your degreee in angular form (dd:mm:ss) to convert it to decimal degrees: ')
82+
list_dms = dms.split(':')
83+
decimal_degree = int(list_dms[0]) + (int(list_dms[1]) / 60) + (int(list_dms[2]) / (60 * 60))
84+
print('The decimal degrees equivalent is', format(decimal_degree, '.2f'), '°')
85+
break
86+
except ValueError:
87+
print('Invalid Format! Unable to convert to decimal degrees!')
88+
89+
#Question 4
90+
import itertools
91+
count = 0
92+
for p in itertools.permutations('123456789'):
93+
s = ''.join(p)
94+
tNum = int(s[0:3])
95+
mNum = int(s[3:6])
96+
lNum = int(s[6:])
97+
if (tNum + mNum == lNum):
98+
print(s)
99+
count = count + 1 #same as count +=1
100+
print('Total number of solutions = ', count)

Diff for: Script-3-Model.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Generated by ArcGIS ModelBuilder on : 2023-02-08 21:31:49
4+
"""
5+
import arcpy
6+
7+
def Model(): # Model
8+
9+
# To allow overwriting outputs change overwriteOutput option to True.
10+
arcpy.env.overwriteOutput = False
11+
12+
CITIES = "CITIES"
13+
intrstat = "intrstat"
14+
15+
# Process: Select (Select) (analysis)
16+
intrstat_Select_2_4 = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_3\\Lab_3_Akunna\\MyProject1.gdb\\intrstat_Select_2_4"
17+
arcpy.analysis.Select(in_features=intrstat, out_feature_class=intrstat_Select_2_4, where_clause="ROUTE_NUM = 'I90'")
18+
19+
# Process: Buffer (Buffer) (analysis)
20+
intrstat_Buffer_4 = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_3\\Lab_3_Akunna\\MyProject1.gdb\\intrstat_Buffer_4"
21+
arcpy.analysis.Buffer(in_features=intrstat_Select_2_4, out_feature_class=intrstat_Buffer_4, buffer_distance_or_field="30 Miles", line_side="FULL", line_end_type="ROUND", dissolve_option="NONE", dissolve_field=[], method="PLANAR")
22+
23+
# Process: Clip (Clip) (analysis)
24+
CITIES_Clip_4 = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_3\\Lab_3_Akunna\\MyProject1.gdb\\CITIES_Clip_4"
25+
arcpy.analysis.Clip(in_features=CITIES, clip_features=intrstat_Buffer_4, out_feature_class=CITIES_Clip_4, cluster_tolerance="")
26+
27+
# Process: Summary Statistics (Summary Statistics) (analysis)
28+
Sum_table_2_4 = "C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_3\\Lab_3_Akunna\\MyProject1.gdb\\Sum_table_2_4"
29+
arcpy.analysis.Statistics(in_table=CITIES_Clip_4, out_table=Sum_table_2_4, statistics_fields=[["POP1990", "SUM"], ["HISPANIC", "SUM"]], case_field=[], concatenation_separator="")
30+
31+
if __name__ == '__main__':
32+
# Global Environment settings
33+
with arcpy.EnvManager(scratchWorkspace=r"C:\Users\akunna1\Desktop\GEOG 592\Lab_3\Lab_3_Akunna\MyProject1.gdb", workspace=r"C:\Users\akunna1\Desktop\GEOG 592\Lab_3\Lab_3_Akunna\MyProject1.gdb"):
34+
Model()

Diff for: Script-3.py

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python
2+
# coding: utf-8
3+
4+
# In[6]:
5+
6+
7+
# -*- coding: utf-8 -*-
8+
"""
9+
#Lab 3
10+
Generated by ArcGIS ModelBuilder on : 2023-02-08 21:31:49
11+
"""
12+
# Question 1 and 2 are in the MS document named lab3
13+
14+
import arcpy
15+
16+
# To allow overwriting outputs change overwriteOutput option to True.
17+
arcpy.env.overwriteOutput = True
18+
arcpy.env.workspace = 'C:\\Users\\akunna1\\Desktop\\GEOG 592\\Lab_3\\Lab_3_Akunna\\'
19+
20+
# Question 3
21+
#Section for configuring input data sources
22+
CITIES = "CITIES.shp"
23+
intrstat = "intrstat.shp"
24+
25+
# Get user's input for two highway choices
26+
hwyListStr = input('Please type two highways to analyze- ExL I40 I80\n')
27+
hwyList = hwyListStr.split()
28+
hw1 = hwyList[0]
29+
bufDistStr = input('Please input the buffer distance values here (in miles): Ex - 30\n')
30+
31+
for aHwy in hwyList:
32+
# Process: Select (Select) (analysis)
33+
intrstat_Select_2_4 = "intrstat_Select.shp"
34+
arcpy.analysis.Select(intrstat, intrstat_Select_2_4, "ROUTE_NUM = '"+aHwy+"'")
35+
36+
# Process: Buffer (Buffer) (analysis)
37+
intrstat_Buffer_4 = "intrstat_Buffer_4.shp"
38+
arcpy.analysis.Buffer(intrstat_Select_2_4, intrstat_Buffer_4, bufDistStr+" Miles", "FULL", "ROUND", "NONE", [], "PLANAR")
39+
40+
# Process: Clip (Clip) (analysis)
41+
CITIES_Clip_4 = "CITIES_Clip_4.shp"
42+
arcpy.analysis.Clip(CITIES, intrstat_Buffer_4, CITIES_Clip_4)
43+
44+
# Process: Summary Statistics (Summary Statistics) (analysis)
45+
Sum_table_2_4 = "Cities"+aHwy+'Buffer'+bufDistStr+".dbf"
46+
arcpy.analysis.Statistics(CITIES_Clip_4, Sum_table_2_4, [["POP1990", "SUM"], ["HISPANIC", "SUM"]])
47+
48+
print(aHwy+ ' just being completed.')
49+
print(' All Completed')
50+
51+
52+
# Question 4
53+
orange_durham = "orange_durham.shp"
54+
CITIES_q4 = "CITIES.shp"
55+
56+
# Process: Clip (Clip) (analysis)
57+
CITIES_Clip_q4 = "cities_clip.shp" # creating a new shape file
58+
arcpy.analysis.Clip(CITIES_q4, orange_durham, CITIES_Clip_q4)
59+
60+
# Process: Buffer (Buffer) (analysis)
61+
cities_Buffer = "cities_buf.shp" # creating a new shape file
62+
arcpy.analysis.Buffer(CITIES_Clip_q4, cities_Buffer, "3 Miles", "FULL", "ROUND", "NONE", [], "PLANAR")
63+
64+
#Deleting the clipped result
65+
arcpy.Delete_management(CITIES_Clip_q4)
66+
67+
68+
#question 5
69+
CITIES_q5 = "CITIES.shp"
70+
71+
# Process: Select (Select) (analysis)
72+
cities_select_q5 = "cities_250000.shp" # creating a new shape file
73+
arcpy.analysis.Select(CITIES_q5, cities_select_q5, "POP1990 > 250000")
74+
75+
76+
# In[ ]:
77+
78+
79+
80+

Diff for: cities.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
City Name, x, y
2+
Greensboro, 1754117, 847860
3+
Durham, 2024027, 811195
4+
Raleigh, 2100008, 755093

0 commit comments

Comments
 (0)