I've tried using two while loops, which is why there's this segment in it:
if len(splitter) == 3:
length = 3
if len(splitter) == 5:
length = 5
But that got me nowhere, and created an infinite return loop of error messages. Infact, it jumped my CPU usage from 25% to 100% very quickly
How can I get the program to only run the splitter[3] and splitter[4] error checking lines only if they're applicable?
Thanks.
calculator_valid = 0
while calculator_valid == 0:
splitter = str(input("Input operands and operations: "))
splitter = splitter.strip()
splitter = splitter.replace('*', 'x*x')
splitter = splitter.replace('/', 'x/x')
splitter = splitter.replace('-', 'x-x')
splitter = splitter.replace('+', 'x+x')
splitter = splitter.split ('x')
print (splitter)
if len(splitter) == 3:
length = 3
if len(splitter) == 5:
length = 5
print(length)
#I thought spacing here would be necessary, given to the lengthy error checking segment.
if (1 > len(splitter)):
print("Please enter a valid input of operand/operator/operand or operand/operator/operand/operator/operand")
elif not(('*') in splitter or ('/') in splitter or ('+') in splitter or ('-') in splitter):
print("Input must include at least one operator")
elif (splitter[0].count('.') > 1):
print("First number error, contains multiple decimal places")
elif (splitter[2].count('.') > 1):
print("Second number error, contains multiple decimal places")
elif (splitter[4].count('.') > 1):
print("Third number error, contains multiple decimal places")
elif (splitter[0].startswith('.')):
print("First number error, number starts with a decimal place")
elif (splitter[0].endswith('.')):
print("First number error, number ends with a decimal place")
elif (splitter[2].startswith('.')):
print("Second number error, number starts with a decimal place")
elif (splitter[2].endswith('.')):
print("Second number error, number ends with a decimal place")
elif (splitter[4].startswith('.')):
print("Third number error, number starts with a decimal place")
elif (splitter[4].endswith('.')):
print("Third number error, number ends with a decimal place")
else:
calculator_valid = 1

New Topic/Question
Reply



MultiQuote





|