【发布时间】:2012-12-15 04:02:09
【问题描述】:
在python中,如果我给x(x = 1)赋值一个1,那么那个1是否每次都被视为一个字符串?
我不明白为什么不将数字视为数字而必须将其转换为 识别用于数学运算的整数。不断改变似乎很麻烦 来回变量值。
谢谢
第 2 部分: 圆面积程序的一些代码:
def chooseDim ( ):
**choice = input ('Do you need to find radius or area? ')
if choice == 'A' or 'a':
area = 0 [This part of the prog is the culprit, specifically the
area = int(area) "choice" variable prior to the If conditional. The If
areaSol ( )** keeps reading the condition as True no matter what value
"choice" is. It has to do w/the "or" condition. When I let
"choice" be one value, it's fine, but if I code
"if choice = 'A' or 'a'" the prog evals the If as True
every time. Am I not coding the "or" statement right?]
elif choice == 'R' or 'r':
radSol ( )
else:
print ('Please enter either A/a or R/r.')
chooseDim ( )
【问题讨论】:
标签: string variables python-3.x int