Python Trading Engine - 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: Python Trading Engine (/thread-3480.html) |
Python Trading Engine - icabero0225 - May-27-2017 So I am trying to code a python script to assist me with my stock trading. here's my code so far. def buy(): datr = float(input("Daily ATR: ")) dzd = float(input("Demand Zone Distal: ")) dzp = float(input("Demand Zone Proximal: ")) szp = float(input("Supply Zone Proximal: ")) szd = float(input("Supply Zone Distal: ")) wr = (datr * 0.02) sl = (dzd - wr) rsk = (dzp - sl) rwd = (rsk * 3) t1 = (dzp + rwd) t2 = szp print("Target 1:", t1) print("Target 2:", t2) def intromenu(): choice = input("1. Buy\n2. Sell\n\nEnter: ") if choice == 1: buy() else: exit() intromenu()When I run the program, I enter 1, the program exits with no errors. I'm trying to make it so whenever I enter 1, the function buy() executes. Thanks. RE: Python Trading Engine - buran - May-27-2017 input return str , and you compare with int , that is why if choice == 1 is always falseobviously you are aware that input return str, because you convert it to float in buy function. RE: Python Trading Engine - icabero0225 - May-27-2017 (May-27-2017, 08:28 PM)buran Wrote: So how would I fix that? I didn't necessarily know that input returns a string, I was just messing around and found that that would get rid of my errors. I'm trying to call function buy()from function intromenu()but can't. RE: Python Trading Engine - bigmit37 - May-27-2017 (May-27-2017, 09:46 PM)icabero0225 Wrote:(May-27-2017, 08:28 PM)buran Wrote: Anything entered as a response to input will be a str .So if input == '1' should work; add quotes around 1.
|