Python Forum
Runs perfect in Python but fails to print last statement when converted to .exe. Help - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Runs perfect in Python but fails to print last statement when converted to .exe. Help (/thread-28992.html)



Runs perfect in Python but fails to print last statement when converted to .exe. Help - sunil422 - Aug-13-2020

This code runs perfect in Python but fails to print last statement(printing calculation) when converted to .exe using pyinstaller. Please Help!

# Defining a function to print error when input is wrong.
def exp():
print('Error! Enter Valid Number')
# Unless entered value is correct ask to enter correct value.
# If the value is wrong call the function
while True:
try:
p=float(input('ENTER SUM'))
break
except:
exp()
# Unless entered value is correct ask to enter correct value.
# If the value is wrong call the function
while True:
try:
r=float(input('ENTER RATE'))
break
except:
exp()
# Unless entered value is correct ask to enter correct value.
# If the value is wrong call the function
while True:
try:
fz=float(input('ENTER TIME IN MONTH'))
break
except:
exp()
t=(fz/12)
# Print the calculation.
print('Interest=Rs',p*t*r/100,'\nAmount to pay=Rs',p+p*t*r/100)


RE: Runs perfect in Python but fails to print last statement when converted to .exe. Help - buran - Aug-13-2020

How do you run the exe? If you just click on it, it will close the window immediately after printing the last line and you just don't see it.
Open cmd, run the exe via command line.
or add a line to wait for user input before finishing the execution.


on a side note - you left that repeating code...


RE: Runs perfect in Python but fails to print last statement when converted to .exe. Help - sunil422 - Aug-13-2020

Thank you so much!


RE: Runs perfect in Python but fails to print last statement when converted to .exe. Help - deanhystad - Aug-13-2020

You can add input('Enter') at the end to hold the window open.