You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Directly accessing First Name from already created array a1
27
+
print"Your First Name is: ",a1[0],"\n"
28
+
29
+
# Directly accessing Last Name from already created array a1
30
+
print"Your Last Name is: ",a1[1],"\n"
31
+
32
+
# Directly accessing Street Number from already created array a2
33
+
print"Your Street Number is: ",a2[0],"\n"
34
+
35
+
# Now since we are trying to find the block Corresponding to Street Letter, we need to access the key in hash Corresponding to the Street Letter in array a2
36
+
# First with a2[1], we access Street Letter then convert it to string and pass it to hash as a key to access Corresponding block
37
+
print"Your Street Letter means: ",hash_add[a2[1].to_s]
# Directly accessing First Name from already created array a1
27
+
print"Your First Name is: ",a1[0],"\n"
28
+
29
+
# Directly accessing Last Name from already created array a1
30
+
print"Your Last Name is: ",a1[1],"\n"
31
+
32
+
# Using Indexing
33
+
# We cannot directly access Street Number from already created array a2 as Street Number and Letter is combined
34
+
# First we extract first element of this array and then we access all elements except the last element which is street letter
35
+
print"Your Street Number using Indexing Method is: ",a2[0].to_s[0,a2[0].length-1],"\n"
36
+
37
+
# Using Chomp method
38
+
# Chomp is used to remove given argument from a variable
39
+
# If we does not give any argument it takes newline as default argument
40
+
# We are using this here for removing the Street Letter from a2[0]
41
+
print"Your Street Number using Chomp Method is: ",a2[0].chomp(a2[0].to_s[-1]),"\n"
42
+
43
+
# Now since we are trying to find the block Corresponding to Street Letter, we need to access the key in hash Corresponding to the Street Letter in array a2
44
+
# First with a2[0], we access first element which is Street Number and Letter then convert it to string
45
+
# Since it is combined with street number,we access the last element using -1 and pass it to hash as a key to access Corresponding block
46
+
print"Your Street Letter means: ",hash_add[a2[0].to_s[-1]]
0 commit comments