I am trying to find the value of totalDistance, but when I type it at the bottom after returning the function: print(totalDistance) I get function is not define. Here is the entire piece I am working on. And what i am trying to get is the value totalDistance because I have to use it to represent the actual number value. Another question is how can I function ordinal so that it shows the "st" "nd" "rd" and "th" were I have str(s1). I am new to this and is hw so nothing fancy if you all may, basic.
i = 1
while i == 1:
s1 = int(input("Starting street: "))
while s1 % 2 == 0:
print("Street must be a positive odd number between 1 and 99!")
s1 = int(input("Starting street: "))
if s1 <= 0:
print("Street must be a positive odd number between 1 and 99!")
s1 = int(input("Starting street: "))
if s1 > 99:
print("Street must be a positive odd number between 1 and 99!")
s1 = int(input("Starting street: "))
a1 = int(input("Starting avenue: "))
while a1 % 2 != 0:
print("Avenue must be a positive even number between 2 and 98!")
a1 = int(input("Starting avenue: "))
if a1 <= 1:
print("Avenue must be a positive even number between 2 and 98!")
a1 = int(input("Starting avenue: "))
if a1 > 98:
print("Avenue must be a positive even number between 2 and 98!")
a1 = int(input("Starting avenue: "))
s2 = int(input("Ending street: "))
while s2 % 2 == 0:
print("Street must be a positive odd number between 1 and 99!")
s2 = int(input("Ending street: "))
if s2 <= 0:
print("Street must be a positive odd number between 1 and 99!")
s2 = int(input("Starting street: "))
if s2 > 99:
print("Street must be a positive odd number between 1 and 99!")
s2 = int(input("Starting street: "))
a2 = int(input("Ending avenue: "))
while a2 % 2 != 0:
print("Avenue must be a positive even number between 2 and 98!")
a2 = int(input("Ending avenue: "))
if a2 <= 1:
print("Avenue must be a positive even number between 2 and 98!")
a2 = int(input("Starting avenue: "))
if a2 > 98:
print("Avenue must be a positive even number between 2 and 98!")
a2 = int(input("Starting avenue: "))
i = i + 1
def getDistance(s1, a1, s2, a2):
streets = (s2 - s1)/2 * 1000
if streets <= -1:
import math
streets = math.fabs(streets)
avenues = (a2 - a1)/2 * 1000
if avenues <= -1:
import math
avenues = math.fabs(avenues)
totalDistance = streets + avenues
return getDistance(s1, a1, s2, a2)
def ordinal(n):
if n % 100/10 != 1:
if n % 10 == 1:
print(str(n) + "st")
elif n % 10 == 2:
print(str(n) + "nd")
elif n % 10 == 3:
print(str(n) + "rd")
else:
print(str(n) + "th")
return ordinal
def getDirections(s1, a1, s2, a2):
print("Directions from " + str(s1) + " and " + str(a1) + " to " + str(s2) + " and " + str(a2))
print("Total distance traveled :" + "ft")
getDirections(s1, a1, s2, a2)
NameError: s1 is not defined, and if I substitute some value for the four variables, your code runs perfectly.