我正在尝试返回def "DMS_to_DD_calculations(x)“中的变量”DMS_to_DD_calculations“。
然后,我希望将该变量赋值给test (我尝试将它赋值为d),以便在def "test(d)“中使用decimal_degrees的值。
# -*- coding: utf-8 -*-
def main():
print "Welcome to the Forward and Back Bearing Calculator"
print "This program displays the back bearing of a given bearing"
print ""
print "How to use:"
print "Type in the value for the bearing then press enter"
print ""
print "Example:"
print "To enter a bearing the following bearing 33°","15'",'22.5"',"would be entered as 33.15225"
print ""
print "The entered bearing will be converted to a back bearing and the result displayed"
print ""
user_input= float(raw_input("DMS bearing:"))
DMS_to_DD_calculations(user_input)
decimal_degrees = test(d)
def DMS_to_DD_calculations(x):
#These 3 functions assign an individual value for the variables: Degrees (d), Minutes (m) and Seconds (s) for the given bearing
# 1. Degrees is equal to the integer value of the user entered bearing
d= int(x)
# 2. Minutes:
# First - Find the user entered value minus the integer of that value times 100.
# Second - The integer of THAT value is the minutes
no_int_m= (x-int(x))*100
int_m= int(no_int_m)
m= int_m
# 3. Seconds:
# First - Find the user entered value minus the integer of that value times 100
# Second - Minus the integer of THAT value is the seconds
s= (no_int_m-int_m)*100
decimal_degrees= (((s/60)+m)/60)+d
print ""
print "DD BEARING =", decimal_degrees,"°"
return decimal_degrees
def test(d):
print "yes"
if decimal_degrees > 0:
print "success"
main()发布于 2016-04-22 10:22:41
使用DMS_to_DD_calculations中的行DMS_to_DD_calculations,可以将decimal_degrees赋值给函数之外的变量(例如dec_degrees = DMS_to_DD_calculations(x))。
然后dec_degrees (或您命名的变量)可以传递到test函数中。
因为函数test没有返回值,所以行decimal_degrees = test(d)将返回None。
另外,由于decimal_degrees不是全局变量,因此需要将其名称更改为d,就像test中的参数名称一样。
https://stackoverflow.com/questions/36790909
复制相似问题