repl.it
@JerryTheMouse/

Experimental Stock Simulation

Python

No description

fork
loading
Files
  • main.py
  • var.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import var as v
def align(word, number):
    return "{:<2}{:>2}".format(word, number)
    # source --> https://stackoverflow.com/questions/19162621/python-3-string-formatting-alignment
print("Welcome to Stock")
while v.quit == False:
  move = input ("Do you want to [B]uy, [S]ell, [Q]uit? ")
  if move.upper() == "B" :
    # Buy 
    print("Here is the current prices:")
    c = 1
    for a, b in v.com.items():
      print(f"{c}.", end = ' ')
      print(align(a + ": ", "$" + str(b) + ' per share'))
      c += 1
    a = input("Please type the one you want to purchase: ")
    shares = input("How many shares of this company do you want to buy? ")
    c = 0
    for a, b in v.com.items():
      c += 1
      if c == a:
        price = a * shares
        if price > v.money:
          print (f"You have to pay ${price} for {shares} of the company.")
  elif move.upper() == "S":
     # Sell
     print('')
  elif move.upper() == 'Q':
    # quit
    print("Quitting application, this application is a simulation and is NOT real stock.")
    v.quit = True
  else:
    print('Invalid Request')
?