0

For the below code, after running start_point = start_point / 10, its value drops to 1,000 and would remain as such if it is called subsequently.

May I know how to reset it to the 10,000 it originally was? I believe one method would be to set a global variable. But is there a simpler way? Like a seek(0)?

def secret_formula(started):
    jelly_beans = started * 500                 
    jars = jelly_beans / 1000                   
    crates = jars / 100                         
    return jelly_beans, crates, jars                

start_point = 10000
item_1, item_2, item_3 = secret_formula(start_point)

print "With a starting point of: %d" % start_point
print "We'd have %d beans, %d jars, and %d crates." % (item_1, item_2, item_3)

start_point = start_point / 10

print "We can also do that this way:"
print "We'd have %d beans, %d jars, and %d crates." % secret_formula(start_point)
2
  • Why do you even save the new value, if you're gonna reset it afterwards anyways? Why not just print "We'd have %d beans, %d jars, and %d crates." % secret_formula(start_point / 10) instead? Commented Dec 2, 2015 at 16:09
  • Thanks for pointing that out. Should have done that! Commented Dec 2, 2015 at 16:32

1 Answer 1

1

would creating another variable work?

original_start_point = 1000
start_point = original_start_point
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, this should work. This way the OP may always revert to the desired "original value" with start_point = original_start_point provided that they only change the start_point variable and don't work with original_start_point otherwise (it doesn't get modified).
Feel free to accept the answer if it satisfies your question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.