-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday8.py
More file actions
58 lines (51 loc) · 1.56 KB
/
Copy pathday8.py
File metadata and controls
58 lines (51 loc) · 1.56 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function
import operator
#input function for both python2.7 and 3
def getInput(prompt=''):
try:
line = raw_input(prompt)
except NameError:
line = input(prompt)
return line
print('Enter/paste content. Ctrl-D to save. ', end='')
user_input = []
while True:
try:
line = getInput()
except EOFError:
break
user_input.append(line)
def getVariables(list):
return_dict = {}
for var in list:
return_dict[var.split()[0]] = 0
return return_dict
def testHighestNumber(number):
global highestNumber
if number > highestNumber:
highestNumber = number
def handleInstructions(list):
global variables
for line in list:
target, direction, diff, start, var1, check, var2 = line.split()
var1 = 'variables[\'' + var1 + '\']'
condition = ' '.join([var1, check, var2])
if (eval(condition)):
if direction == 'inc':
variables[target] += int(diff)
testHighestNumber(variables[target])
elif direction == 'dec':
variables[target] -= int(diff)
testHighestNumber(variables[target])
def main():
global variables
global highestNumber
highestNumber = 0
variables = {}
variables = getVariables(user_input)
handleInstructions(user_input)
print(max(variables.iteritems(), key=operator.itemgetter(1)))
print('highest held number during operation:',highestNumber)
main()