Exponential

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

Exponential

Postby el_manu » Mon Aug 26, 2013 4:10 am

EDIT:
LOOK BELOW I ALREADY DID IT

Code: Select all
mimi = int(input("Number of cells: "))
my = mimi
karpos = 6900000000
while mimi <= karpos and mimi >0
    mimi = mimi * 2
    hello = mimi
    yaya = hello/my
a0 = 1
a1 = 2
a2 = 4
a3 = 8
a4 = 16
a5 = 32
a6 = 64
a7 = 128
a8 = 256
a9 = 512
a10 = 1024
a11 = 2048
a12 = 4096
a13 = 8192
a14 = 16384
a15 = 32768
a16 = 65536
a17 = 131072
a18 = 262144
a19 = 524288
a20 = 1048576
a21 = 2097152
a22 = 4194304
a23 = 8388608
a24 = 16777216
a25 = 33554432
a26 = 67108864
a27 = 134217728
a28 = 268435456
a29 = 536870912
a30 = 1073741824
a31 = 2147483648
a32 = 4294967296
a33 = 8589934592
a34 = 17179869184
a35 = 34359738368
a36 = 68719476736
a37 = 137438953472
a38 = 274877906944
a39 = 549755813888
a40 = 1099511627776
a41 = 2199023255552
a42 = 4398046511104
a43 = 8796093022208
a44 = 17592186044416
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)


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

Postby el_manu » Mon Aug 26, 2013 4:14 am

i got it don't worry

Code: Select all
mimi = int(input("Number of cells: "))
my = mimi
karpos = 6900000000
while mimi <= karpos and mimi >0:
    mimi = mimi * 2
    hello = mimi
    yaya = hello/my
a0 = 1
a1 = 2
a2 = 4
a3 = 8
a4 = 16
a5 = 32
a6 = 64
a7 = 128
a8 = 256
a9 = 512
a10 = 1024
a11 = 2048
a12 = 4096
a13 = 8192
a14 = 16384
a15 = 32768
a16 = 65536
a17 = 131072
a18 = 262144
a19 = 524288
a20 = 1048576
a21 = 2097152
a22 = 4194304
a23 = 8388608
a24 = 16777216
a25 = 33554432
a26 = 67108864
a27 = 134217728
a28 = 268435456
a29 = 536870912
a30 = 1073741824
a31 = 2147483648
a32 = 4294967296
a33 = 8589934592
a34 = 17179869184
a35 = 34359738368
a36 = 68719476736
a37 = 137438953472
a38 = 274877906944
a39 = 549755813888
a40 = 1099511627776
a41 = 2199023255552
a42 = 4398046511104
a43 = 8796093022208
a44 = 17592186044416
if 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

Postby Mekire » Mon Aug 26, 2013 4:54 am

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 = 6900000000
cycles = 0
while 0 < mimi <= karpos  :
    mimi *= 2
    cycles += 1
print("Number of cycles: {}".format(cycles))
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Exponential

Postby micseydel » Mon Aug 26, 2013 5:47 am

"Oh my god. Oh my GOD. OH MY GOD!"
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1390
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Exponential

Postby el_manu » Mon Aug 26, 2013 5:56 am

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

Postby el_manu » Mon Aug 26, 2013 5:59 am

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

Postby el_manu » Mon Aug 26, 2013 6:04 am

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 = 6900000000
cycles = 0
while 0 < mimi <= karpos  :
    mimi *= 2
    cycles += 1
print("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

Postby Mekire » Mon Aug 26, 2013 6:12 am

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
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], micseydel and 4 guests