Итак, вот мой сценарий:Что не так в моем скрипте 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
@Hackaholic' 1.0/3.0', '1.0/3.0',' 2 * (3/4 + 1) 'и некоторые базовые математические данные, такие как' 1 + 1', и скоро '3 * (4/а-3) == 4/(а-1)'. –
Несколько указателей, не связанных с непосредственной проблемой, с которой вы сталкиваетесь: ввод функций в цикле фактически переопределяет их каждый раз - вы можете вывести их на верхний уровень. Сравнение 'b == exit' не будет работать - во-первых, b уже является числом; во-вторых, вы сравниваете с функцией 'exit' not string' "exit" '. Вы можете использовать фактические логические значения, поэтому вы, вероятно, хотите 'on = True' и' while on: '. В сценарии есть и другие необычные вещи: я бы посоветовал вам начать с более простых шагов и убедиться, что они работают правильно, прежде чем создавать для них больше кода. – viraptor