所以,这是我的剧本:
#Imports
import decimal
#variables
neweq = "neweq"
on = 1
#loop
while on > 0:
#equasion function
def eq ():
global b
b = input("Please enter an equation (Example: 10*(3*a)==4*(7*a), or 3.0/7.0). Unfortunately however, you can only use the variable 'a'. Also, you can type 'exit' to quit: ")
print ""
print ""
print ""
print ""
b = float(b)
b = '%.3f'%(b)
if (b==exit):
print ""
print ""
print ""
print ""
print ""
print ""
print ""
print ""
exit ("Thank you for using me :)")
#input funcution
def inp ():
a = input("Enter numeral (Example: 1, or 1.5) to proceed, 'exit' to quit, or 'neweq' to enter a new equasion: ")
if (a==exit):
print ""
print ""
print ""
print ""
print ""
print ""
print ""
print ""
print ""
exit ("Thank you for using me :)")
if (a == neweq):
print ""
print ""
a = 0
eq ()
inp()
if (b==a):
print ""
print "Yes, the answer is", a
print ""
print ""
eq ()
else:
print ""
print "No, the answer is not", a
print ""
print ""
print "test line", b
inp ()
#function calls
eq()
inp ()
有什么问题吗?你知道吗
Please enter an equation (Example: 10*(3*a)==4*(7*a), or 3.0/7.0). Unfortunately however, you can only use the variable 'a'. Also, you can type 'exit' to quit: 2.0/4.0
Enter numeral (Example: 1, or 1.5) to proceed, 'exit' to quit, or 'neweq' to enter a new equasion: 1/2
No, the answer is not 0
test line 0.500
Enter numeral (Example: 1, or 1.5) to proceed, 'exit' to quit, or 'neweq' to enter a new equasion: 102.0
No, the answer is not 102.0
test line 0.500
Enter numeral (Example: 1, or 1.5) to proceed, 'exit' to quit, or 'neweq' to enter a new equasion: 1.0/2.0
No, the answer is not 0.5
test line 0.500
Enter numeral (Example: 1, or 1.5) to proceed, 'exit' to quit, or 'neweq' to enter a new equasion: .500
No, the answer is not 0.5
test line 0.500
Enter numeral (Example: 1, or 1.5) to proceed, 'exit' to quit, or 'neweq' to enter a new equasion: 0
No, the answer is not 0
test line 0.500
Enter numeral (Example: 1, or 1.5) to proceed, 'exit' to quit, or 'neweq' to enter a new equasion: 4.0/2.0
No, the answer is not 2.0
test line 0.500
Enter numeral (Example: 1, or 1.5) to proceed, 'exit' to quit, or 'neweq' to enter a new equasion: 2.0/4.0
No, the answer is not 0.5
test line 0.500
Enter numeral (Example: 1, or 1.5) to proceed, 'exit' to quit, or 'neweq' to enter a new equasion: 0.500
No, the answer is not 0.5
test line 0.500
Enter numeral (Example: 1, or 1.5) to proceed, 'exit' to quit, or 'neweq' to enter a new equasion:
它应该返回'是的,答案是0.5',但是,它不是。与其他几个等式相同。我不知道它有什么问题,但是,我怀疑它是b = '%.3f'%(b)
,这就是我需要帮助的地方。你知道吗
谢谢你!你知道吗
给你。我已经编辑了你的代码。让我知道如果这是你想要的,我不知道你为什么用
print ""
,我把它移到这里,因为它伤害了我的眼睛!:P.也请不要使用exit
作为用户的输入使用“quit”最好。解释一下可以在评论中找到。你知道吗如果您使用
print""
来避免工作空间的混乱,那么可以这样尝试这是更整洁和Python。你知道吗
此位看起来可疑,它(可能)需要一个字符串并尝试将其转换为浮点:
相关问题 更多 >
编程相关推荐