Skip to content

Instantly share code, notes, and snippets.

@iminurnamez
Forked from craig3050/gist:10985630
Last active August 29, 2015 13:59
Show Gist options
  • Save iminurnamez/10987357 to your computer and use it in GitHub Desktop.
Save iminurnamez/10987357 to your computer and use it in GitHub Desktop.
a few suggestions
#!/usr/bin/python
from random import randint, choice
def return_list(num_to_try,numbers_dictionary):
first = randint(1,6)
list_fig = [int(numbers_dictionary[first])]
called = [first]
x = 1
while x < num_to_try:
y = randint(1,6)
if y not in called:
list_fig.append(int(numbers_dictionary[y]))
called.append(y)
x += 1
return list_fig
def operator():
#x = randint(1,4)
#if x == 1:
# return "addition"
#if x == 2:
# return "subtraction"
#if x == 3:
# return "multiplication"
#if x == 4:
return choice(("addition", "subtraction", "division", "multiplication"))
def takes_two(a, b, operation):
operations = {"addition": float(a + b),
"subtraction": float(a - b),
"multiplication": float(a * b),
"division": float(a / b)}
return operations[operation]
def check_target(list):
x = len(list)
count = 1
total = list[0]
final_list = [float(total)]
while count < x:
op = operator()
second = list[count]
total = takes_two(total,second,op)
count += 1
#final_list.append(op)
#final_list.append(second)
#final_list.append(" = ")
#final_list.append(float(total))
final_list.extend([op, second, " = ", float(total)])
return (total, final_list)
def main():
print "********************************"
print "*** Welcome to the Countdown ***"
print "*** Number Puzzle Solver ***"
print "********************************"
numbers_dictionary = {} # Empty
prompts = ["first", "second",
"third", "fourth",
"fifth", "sixth"]
for i, prompt in enumerate(prompts, start=1):
full_prompt = "Enter {} number:".format(prompt)
numbers_dictionary[i] = raw_input(full_prompt)
target = int(raw_input("Enter the Target Number"))
total = 0
while target != total:
num_to_try = randint(1,6)
(total , final_list) = check_target(return_list(num_to_try,numbers_dictionary))
print total
print final_list
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment