工作在小范围的圆圈编。我一直无法解决调试阶段出现的问题。诸如“变量在外部引用...”之类的错误以及其他不会处理简单方程的错误(例如,半径 = 面积 / PI * 半径)。我尝试了很多方法来解决这个问题,除了重写整个 prog,但没有任何效果。我的解决方案要么产生新问题,要么不解决手头的问题。我已经学习了三个星期的 Python,但确实有使用 COBOL 的编码经验,所以我了解函数和流程图的概念。
当您没有解决问题的头脑或工具时,您会怎么做?我想自己解决这些问题。寻求帮助是明智的,但最终你必须自己飞行。
谢谢你的帮助。
通量
添加:
圆和半径的面积:
# Exercise 1 Area of Circle
# This prog will ask for circle dimensions and compute
# area/radius for the user, then display figures, and
# allow to repeat.
import sys
import pdb
PI = 3.14
radius = 0
print ('''Welcome to Ursavion, the leader in math apps
This app allows you to quickly and easily find
either the area or radius for a circle.''')
print ( )
def chooseAR ( ):
print ('Do you need to find circle area or circle radius? Enter A/a or A/r. ')
choice = input ( )
if choice in ['A', 'a']:
areaSol ( )
elif choice in ['R', 'r']:
radSol (radius)
else:
print ('Please enter either A/a or R/r. ')
chooseAR ( )
def areaSol ( ):
radius = 0
radius = input ('What is the radius of the circle? ')
radius = int (radius)
area = PI * radius**2
radius = str(radius)
area = str(area)
print ('The area of a circle with radius ' + radius + ' is ' + area + ' units ' squared')
print ( )
print ('Calculate another? y/n ')
again = input ( )
if again in [ 'y', 'n']:
chooseAR ( )
else:
print ('Thank you for using this app.')
def radSol (radius):
#pdb.set_trace( ) #r = 1.128 for A = 4
area = input ('What is the area of the circle? ')
area = int(area)
radius = int(radius)
radius = area / 3.14 * radius #prog will not eval this formula; float pt prob
radius = str(radius)
area = str(area)
print ('The radius of a circle with area ' + str(area) + ' is ' + str(radius) + ' units')
print ( )
again = input ('Calculate another? y/n ')
if again in ['Y', 'y', 'N', 'n']:
chooseAR( )
else:
print ('Thank you for using this app.')
chooseAR ( ) # This function is one problem. Program initializes all
# functions on first pass, but it needs "chooseAR" here to allow the
# program to start, else it never runs; however, the "chooseAR" sets up
# an infinite loop if it exists here.