在编程中,我正在编写一个用户选择实体的代码,然后计算体积和表面积.但是我没有直接选择,而是向用户提供了询问有关实体的额外信息的选项,如果他们输入数字然后"显示"(例如'1 show').他们可以继续询问,直到选择一个实体,所以我使用了一个while循环.
循环不起作用.如果循环的条件无效,它仍会进入循环并且不让我离开.请帮忙.我觉得这很简单.我试图进行整数和字符串转换,没有它帮助.
#11/07/12
#A program that asks user for input and calculates SA and Volume of a chosen solid
print "Which solid would you like to calculate?"
print " "
print "1. Tetrahedron"
print "2. Dodecahedron"
print "3. Cone"
print "4. Sphere"
print "5. Icosahedron"
print ' '
print "If you want extra information on the solid, enter the solid's number and then add show. Example: 1 show"
print "If not, just enter the number"
choice = raw_input('----->')
#Where …Run Code Online (Sandbox Code Playgroud) 在python中显示操作失败的正确方法是什么.在这段代码中,返回值应该是什么?
def compare(y,x):
if y == x:
return 'true'
return 'false'
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个非常基本的帐户减钱系统我正在使用的代码询问用户是否愿意购买价格为200美元的物品.这个想法是200美元将从命名的变量中扣除,total但由于某种原因,这是行不通的.
我不知道是否可以在if语句中嵌套For循环.感谢您的时间
total = 1500
print('Would you like to buy this item?')
print('It costs 100 bucks')
purchaseConfirm = input()
if purchaseConfirm == 'yes':
for num in range(200):
total = total-1 # Why is this thing not functioning???
print(total)
break
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Python来拆分字符串,如下所示:
10004, 10005, 0,'1 ',2,2,1, 0.00000E+0, 0.00000E+0, 2, 'ALCAZAR,NMRD ',1, 129,1.0000
Run Code Online (Sandbox Code Playgroud)
我想说"ALCAZAR,NMRD "一句话.显然,如果我","用作分离器str.split(),这个单词将被分成两个字符串.我正在考虑"," 用空格替换这个词,然后用它","作为分割器来分割整行.但是str.replace()没有给我指定开始或结束的位置.非常感谢您的反馈.
我正在使用qpython3.班级没有改变int().以下是qpython3控制台中的示例代码.
>>> a = "8"
>>> a
'8'
>>> type(a)
<class 'str'>
>>> int(a)
8
>>> type(a)
<class 'str'>
Run Code Online (Sandbox Code Playgroud)
该类保持字符串.将int赋值给变量作为对比:
>>> a = 8
>>> a
8
>>> type(a)
<class 'int'>
Run Code Online (Sandbox Code Playgroud)
这里的问题是如果int从中获取一个字符 input(),则禁止进一步的数学运算和逻辑比较.