-
Notifications
You must be signed in to change notification settings - Fork 0
/
.NumberProducer.py
154 lines (131 loc) · 4.18 KB
/
.NumberProducer.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import sys
from termcolor import colored
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Number Producer
@author Ryan Thompson
Prints out desired amount of numbers,
in either integer or float format.
python NumberProducer.py <i||f> <n> <base(float only)>
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Setting some constants
COLOR = "green"
COLOR_INT = "cyan"
COLOR_FLOAT = COLOR_INT # Got tired of picking different colors
COLOR_ENDS = "grey"
# Ask for integers or floats.
def getOption():
print(colored("Pick integers<i>, floats<f>, or letter<l> ", COLOR, attrs=["bold"]),end="")
choice = input()
return choice
# Checking for cmd arguments.
# If no cmd args are provided, proceed
# to asking for args via terminal.
def argsCheck(firstList):
tmp = []
totalArgs = len(sys.argv)
if(totalArgs > 1 and firstList == True):
tmp.append(sys.argv[1]) # int or float
tmp.append(sys.argv[2]) # amount of numbers
if(totalArgs > 3):
tmp.append(sys.argv[3]) # base value for floats
else:
decision = getOption()
tmp.append(decision)
return tmp
# Base of numbers. x.y
# Base = x
# ex) x=15 --> 15.y
def getBase():
print(colored("Enter base value: ", COLOR, attrs=["bold"]), end="")
retVal = input()
return retVal
# Set & get amount of numbers
def getAmount():
print(colored("Enter amount needed: ", COLOR, attrs=["bold"]), end="")
n = input()
return n
# Print integers
def intPrinter(n):
for i in range(n):
print(colored(str(i+1) + ")", COLOR_INT, attrs=["bold"]))
# Print floats
def floatPrinter(baseVal, n):
for i in range(n):
print(colored(str(baseVal) + "." + str(i+1) + ")", COLOR_FLOAT, attrs=["bold"]))
# Print letter-list
# Starts at the charater a
def letterPrinter():
a = 97
print(colored("\n<Letter-list starts at 'a'>", "green"))
print(colored("Enter final letter: ", COLOR, attrs=["bold"]), end="")
finalLetter = input()[0].lower()
n = ord(finalLetter) - a +1
for i in range(n):
print(colored(str(chr((a+i))) + ")", COLOR_INT, attrs=["bold"]))
# Final setup for integers or floats
def makeFire(firstRound):
exit = False
args = argsCheck(firstRound)
numArgs = len(args)
n = 0
decision = args[0] # Getting choice of int or float
base = 0
# Runnning cmd args
if(numArgs > 1):
#decision = args[0]
n = args[1]
n = int(n)
if(numArgs == 3 and decision == "f"):
base = args[2]
floatPrinter(base, n)
else:
intPrinter(n)
# Getting args via terminal.
elif(numArgs <= 1):
#decision = args[0]
if(decision == 'n'):
exit = True
return exit
elif(decision == "l"):
letterPrinter()
else:
n = getAmount()
n = int(n)
# Going the float route.
if(decision == "f"):
base = getBase()
floatPrinter(base, n)
# Going the integer route
if(decision == "i"):
intPrinter(n)
# if(decision == "n"):
# exit = True
return exit
# Singals the start and end of this program,
# inside of the terminal.
def printLimit(point):
print(colored("\n-----------------------------------------------------", COLOR_ENDS, attrs=["bold"]))
print(colored("NumberProducer.py " + str(point), COLOR_ENDS, attrs=["bold"]))
print(colored("-----------------------------------------------------\n", COLOR_ENDS, attrs=["bold"]))
# Driver function
def main():
print() # Buffer white-space in terminal
printLimit("START") # Opening
stop = False
roundOne = True
# Keeps producing number-lists until stop == true.
while(stop == False):
stop = makeFire(roundOne)
roundOne = False
if(stop == False):
print(colored("Would you like another list of numbers? <y/n> ",COLOR, attrs=["bold"]), end="")
else:
continue
pick = input().lower()
print()
if(pick == "n" or pick == "no"): # Make it stop
stop = True
printLimit("END") # Closing
print() # Buffer white-space in terminal
# The big red button
main()