Exponential

This is the place for queries that don't fit in any of the other categories.

Exponential

EDIT:
LOOK BELOW I ALREADY DID IT

Code: Select all
`mimi = int(input("Number of cells: "))my = mimikarpos = 6900000000while mimi <= karpos and mimi >0    mimi = mimi * 2    hello = mimi    yaya = hello/mya0 = 1a1 = 2a2 = 4a3 = 8a4 = 16a5 = 32a6 = 64a7 = 128a8 = 256a9 = 512a10 = 1024a11 = 2048a12 = 4096a13 = 8192a14 = 16384a15 = 32768a16 = 65536a17 = 131072a18 = 262144a19 = 524288a20 = 1048576a21 = 2097152a22 = 4194304a23 = 8388608a24 = 16777216a25 = 33554432a26 = 67108864a27 = 134217728a28 = 268435456a29 = 536870912a30 = 1073741824a31 = 2147483648a32 = 4294967296a33 = 8589934592a34 = 17179869184a35 = 34359738368a36 = 68719476736a37 = 137438953472a38 = 274877906944a39 = 549755813888a40 = 1099511627776a41 = 2199023255552a42 = 4398046511104a43 = 8796093022208a44 = 17592186044416if my > karpos:   print("Number of cycles:", 0)elif yaya == a1:   print("Number of cycles:", 1)elif yaya == a2:   print("Number of cycles:", 2)elif yaya == a3:   print("Number of cycles:", 3)elif yaya == a4:   print("Number of cycles:", 4)elif yaya == a5:   print("Number of cycles:", 5)elif yaya == a6:   print("Number of cycles:", 6)elif yaya == a7:   print("Number of cycles:", 7)elif yaya == a8:   print("Number of cycles:", 8)elif yaya == a9:   print("Number of cycles:", 9)elif yaya == a10:   print("Number of cycles:", 10)elif yaya == a11:   print("Number of cycles:", 11)elif yaya == a12:   print("Number of cycles:", 12)elif yaya == a13:   print("Number of cycles:", 13)elif yaya == a14:   print("Number of cycles:", 14)elif yaya == a15:   print("Number of cycles:", 15)elif yaya == a16:   print("Number of cycles:", 16)elif yaya == a17:   print("Number of cycles:", 17)elif yaya == a18:   print("Number of cycles:", 18)elif yaya == a19:   print("Number of cycles:", 19)elif yaya == a20:   print("Number of cycles:", 20)elif yaya == a21:   print("Number of cycles:", 21)elif yaya == a22:   print("Number of cycles:", 22)elif yaya == a23:   print("Number of cycles:", 23)elif yaya == a24:   print("Number of cycles:", 24)elif yaya == a25:   print("Number of cycles:", 25)elif yaya == a26:   print("Number of cycles:", 26)elif yaya == a27:   print("Number of cycles:", 27)elif yaya == a28:   print("Number of cycles:", 28)elif yaya == a29:   print("Number of cycles:", 29)elif yaya == a30:   print("Number of cycles:", 30)elif yaya == a31:   print("Number of cycles:", 31)elif yaya == a32:   print("Number of cycles:", 32)elif yaya == a33:   print("Number of cycles:", 33)elif yaya == a34:   print("Number of cycles:", 34)elif yaya == a35:   print("Number of cycles:", 35)elif yaya == a36:   print("Number of cycles:", 36)elif yaya == a37:   print("Number of cycles:", 37)elif yaya == a38:   print("Number of cycles:", 38)elif yaya == a39:   print("Number of cycles:", 39)elif yaya == a40:   print("Number of cycles:", 40)elif yaya == a41:   print("Number of cycles:", 41)elif yaya == a42:   print("Number of cycles:", 42)elif yaya == a43:   print("Number of cycles:", 43)elif yaya == a44:   print("Number of cycles:", 44)`

it says:
Traceback (most recent call last):
File "program.py", line 55, in <module>
elif yaya == a1:
NameError: name 'yaya' is not defined

i know why but how can i fix this????
i want it to do nothing when 0 is inputed
Last edited by el_manu on Mon Aug 26, 2013 4:15 am, edited 1 time in total.
el_manu

Posts: 87
Joined: Mon Aug 19, 2013 8:30 am

Re: Exponential

i got it don't worry

Code: Select all
`mimi = int(input("Number of cells: "))my = mimikarpos = 6900000000while mimi <= karpos and mimi >0:    mimi = mimi * 2    hello = mimi    yaya = hello/mya0 = 1a1 = 2a2 = 4a3 = 8a4 = 16a5 = 32a6 = 64a7 = 128a8 = 256a9 = 512a10 = 1024a11 = 2048a12 = 4096a13 = 8192a14 = 16384a15 = 32768a16 = 65536a17 = 131072a18 = 262144a19 = 524288a20 = 1048576a21 = 2097152a22 = 4194304a23 = 8388608a24 = 16777216a25 = 33554432a26 = 67108864a27 = 134217728a28 = 268435456a29 = 536870912a30 = 1073741824a31 = 2147483648a32 = 4294967296a33 = 8589934592a34 = 17179869184a35 = 34359738368a36 = 68719476736a37 = 137438953472a38 = 274877906944a39 = 549755813888a40 = 1099511627776a41 = 2199023255552a42 = 4398046511104a43 = 8796093022208a44 = 17592186044416if mimi >0:   if my > karpos:      print("Number of cycles:", 0)   elif yaya == a1:      print("Number of cycles:", 1)   elif yaya == a2:      print("Number of cycles:", 2)   elif yaya == a3:      print("Number of cycles:", 3)   elif yaya == a4:      print("Number of cycles:", 4)   elif yaya == a5:      print("Number of cycles:", 5)   elif yaya == a6:      print("Number of cycles:", 6)   elif yaya == a7:      print("Number of cycles:", 7)   elif yaya == a8:      print("Number of cycles:", 8)   elif yaya == a9:      print("Number of cycles:", 9)   elif yaya == a10:      print("Number of cycles:", 10)   elif yaya == a11:      print("Number of cycles:", 11)   elif yaya == a12:      print("Number of cycles:", 12)   elif yaya == a13:      print("Number of cycles:", 13)   elif yaya == a14:      print("Number of cycles:", 14)   elif yaya == a15:      print("Number of cycles:", 15)   elif yaya == a16:      print("Number of cycles:", 16)   elif yaya == a17:      print("Number of cycles:", 17)   elif yaya == a18:      print("Number of cycles:", 18)   elif yaya == a19:      print("Number of cycles:", 19)   elif yaya == a20:      print("Number of cycles:", 20)   elif yaya == a21:      print("Number of cycles:", 21)   elif yaya == a22:      print("Number of cycles:", 22)   elif yaya == a23:      print("Number of cycles:", 23)   elif yaya == a24:      print("Number of cycles:", 24)   elif yaya == a25:      print("Number of cycles:", 25)   elif yaya == a26:      print("Number of cycles:", 26)   elif yaya == a27:      print("Number of cycles:", 27)   elif yaya == a28:      print("Number of cycles:", 28)   elif yaya == a29:      print("Number of cycles:", 29)   elif yaya == a30:      print("Number of cycles:", 30)   elif yaya == a31:      print("Number of cycles:", 31)   elif yaya == a32:      print("Number of cycles:", 32)   elif yaya == a33:      print("Number of cycles:", 33)   elif yaya == a34:      print("Number of cycles:", 34)   elif yaya == a35:      print("Number of cycles:", 35)   elif yaya == a36:      print("Number of cycles:", 36)   elif yaya == a37:      print("Number of cycles:", 37)   elif yaya == a38:      print("Number of cycles:", 38)   elif yaya == a39:      print("Number of cycles:", 39)   elif yaya == a40:      print("Number of cycles:", 40)   elif yaya == a41:      print("Number of cycles:", 41)   elif yaya == a42:      print("Number of cycles:", 42)   elif yaya == a43:      print("Number of cycles:", 43)   elif yaya == a44:      print("Number of cycles:", 44)`
el_manu

Posts: 87
Joined: Mon Aug 19, 2013 8:30 am

Re: Exponential

As you didn't state the original problem in your posts (or you edited it out), all I can tell you is you are doing this completely incorrectly. This looks like it would be absolutely trivial with a simple loop. Please repost the problem if you would like actual assistance.

-Mek

Edit:
Doesn't this accomplish the exact same thing?
Code: Select all
`mimi = int(input("Number of cells: "))karpos = 6900000000cycles = 0while 0 < mimi <= karpos  :    mimi *= 2    cycles += 1print("Number of cycles: {}".format(cycles))`
New Users, Read This
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Describe your problem; not your chosen solution.
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

Re: Exponential

"Oh my god. Oh my GOD. OH MY GOD!"
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Exponential

Crap. Yeah you are correct.

i didn't post the question because it wasn't needed in answering my question, but i wasted hours of my time putting in all the values to do this.

i figured out the exponential formula, y = a*((b)**x))
in the case of my question b equalled 2.
a equals the input and from there, y equalled the final thing of a after the while loop.
then u divide both sides by a.
and then you are left with 2 to the power of x = a number

to find x (which is the number of cycles), i can do it on paper and calculator using log, but couldn't use common sense and brain power and log on python.
el_manu

Posts: 87
Joined: Mon Aug 19, 2013 8:30 am

Re: Exponential

micseydel wrote:"Oh my god. Oh my GOD. OH MY GOD!"

i know.

after working on it for 2 hours without success, i just did it the harder and time consuming way
el_manu

Posts: 87
Joined: Mon Aug 19, 2013 8:30 am

Re: Exponential

Mekire wrote:As you didn't state the original problem in your posts (or you edited it out), all I can tell you is you are doing this completely incorrectly. This looks like it would be absolutely trivial with a simple loop. Please repost the problem if you would like actual assistance.

-Mek

Edit:
Doesn't this accomplish the exact same thing?
Code: Select all
`mimi = int(input("Number of cells: "))karpos = 6900000000cycles = 0while 0 < mimi <= karpos  :    mimi *= 2    cycles += 1print("Number of cycles: {}".format(cycles))`

can you explain what your while loop does??, and wat *= and += means??

thanks
el_manu

Posts: 87
Joined: Mon Aug 19, 2013 8:30 am

Re: Exponential

Code: Select all
`a += 1`
Is identical to
Code: Select all
`a = a+1`

Same goes for *=
Code: Select all
`a *= 2`
is the same as
Code: Select all
`a = a*2`

See here for more information:
http://docs.python.org/release/2.5.2/ref/augassign.html

-Mek
New Users, Read This
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Describe your problem; not your chosen solution.
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 8 guests