所以,這裏是我的腳本:我的python腳本有什麼問題?
#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)
,這就是我需要幫助的地方。
謝謝!
你可以告訴我,什麼輸入將被期望?就像'float/float' – Hackaholic 2014-11-05 04:48:43
@Hackaholic'1.0/3.0','1.0/3.0','2 *(3/4 + 1)'和一些基本的數學例如'1 + 1',並且很快就會'3 *(4/A-3)== 4 /(A-1)'。 – 2014-11-05 04:57:57
與您遇到的直接問題無關的幾個指針:將函數放入循環中實際上每次都重新定義它們 - 您可以將它們帶到最高級別。比較'b == exit'將不起作用 - 首先,b已經是一個數字;第二,你正在比較函數'exit'而不是string'「exit」'。你可以使用實際的布爾值,所以你可能想'on = True'和'while on:'。腳本中還有其他不常用的東西 - 我建議您先從簡單的步驟開始,並在圍繞它們構建更多代碼之前驗證它們是否正常工作。 – viraptor 2014-11-05 05:09:51