 |
|
 |
Mike Stratton wrote: x = 16
while x > 0
x = x * x
Have you looked carefully at these statements?
|
|
|
|
 |
|
 |
The answer is simple really, I actually purposely created this code while learning python via MIT OpenCourseWare.
This code creates an infinte loop with the number calculations increasing beyond Pythons capabilities very quickly.
I thought it was kind of funny as the code says:
x is equal to 16
If you find that x is greater then 0 then do the following:
redefine x as is equal to 16*16
Second loop:
x is equal to 256
if you find that x is greater then 0 then do the following
redefine x as equalt to 256*256
Third loop:
x is equal to 65536
if you find that x is greater then 0 then do the following
redefine x as equal to 65536 * 65536
A few loops and python cannot compute.
|
|
|
|
 |
|
 |
x = 16
while x > 0:
x = x * x
You were just missing a :
and statements under a while, or for, or if, etc
must be indented
try it now
Mike
|
|
|
|
 |
|
 |
x = 16
while x > 0 :
x = x * x
Pavan Pareta
|
|
|
|
 |
|
 |
Is this supposed to add some value here?
|
|
|
|
 |
|
 |
The value added is a good laugh.
I am just having fun learning to code.
|
|
|
|
 |
|
 |
And the purpose of posting the question was what?
|
|
|
|
 |
|
 |
post = "function"
while input = 'function?':
print 'That was funny!'
else:
print 'That was Stupid'
|
|
|
|
 |
|
 |
My purpose was to try and find other programmers that share my enthusiasm for learning.
Have a good day.
|
|
|
|
 |
|
 |
This answer is partially correct.
Yes I forget the operative of : when typing this but the real problem is that it creates an infinite loop that causes Pythong to crash.
|
|
|
|
 |
|
 |
If you understand why it crashed, then it was a worthwhile exercise.
Clue: the infinite loop isn't why it crashed. It crashed after just 3 iterations, so there must be something else happening here. (Another clue: think powers of 2)
|
|
|
|
 |
|
 |
I would have to say it is neither the infinite loop, nor the multipication. The reason for the crash is quite clearly evidence of the programmers inability!
|
|
|
|
 |
|
 |
This question was rhetorical, and intended as a joke.
Looks like my humor is about as good as my programming skills and grammor.
----- Just excited to be learning about Python -----
|
|
|
|
 |
|
 |
I for one thank you for the test.
I know c and pascal and... but just learning python. this exercise was vary useful for me and I got several loops (18) before the system bogged down for 1 min and the printout started to mess up.
|
|
|
|
 |
|
 |
How to write a script that uses a control statement (such as FOR loops, WHILE loops, etc...) to print out 50 lines using variables as shown in Figure 1. Note that Line 3 is derived by adding Line 1 & 2. Line 4 is derived by adding Line 2 & 3 and so on…
Line 1 : 1
Line 2 : 1
Line 3 : 2
Line 4 : 3
Line 5 : 5
Line 6 : 8
Line 7 : 13
Line 8 : 21
…
…
Figure1.
Output from executed script
Smaini
|
|
|
|
 |
|
 |
q = [0,1]
for i in range(1,50):
sum = q[0] + q[1]
print 'Line %d : %d' % (i,sum)
if i > 1:
q = [ q[1], sum ]
MBH
|
|
|
|
 |
|
 |
Ok thanks for your suggestion!!
|
|
|
|
 |
|
 |
Hey, i was wondering where i can find some decent python tutorials that i can download in the PDF format???
Your help will be greatly appreciated.
Todd.
|
|
|
|
 |
|
 |
Greetings:
Although you'll end up getting all of the Python documentation, including the language reference and C API, the tutorials over at Python's official site, python.org are still some of the best around: http://docs.python.org/download.html[^]
For practical applications and uses for Python, Mark Pilgrim's Dive Into Python is also a tremendous resource: http://diveintopython.org/#download[^]
I hope this was of help....
|
|
|
|
 |
|
|
 |
|
 |
Is there any module in python for extracting cab files.
|
|
|
|
 |
|
|
 |
|
 |
Whoops, just realised that msilib doesn't read CAB files it only creates them. Sorry about that.
|
|
|
|
 |
|
 |
Yes. Its called the Windows API, which has in built CAB support.
If everything was not true, would it be not true that everything is not true? So by saying everything is not true, you are automatically denying that everything is not true. Im so confused...
FreeDOS
- An open source modern
MS-DOS/PC-DOS replacement.
|
|
|
|
 |
|
 |
Wow, sarcastic and devoid of content. Bravo. Add a stupid character to the end of your handle and win a prize. You're a winner. First off, it's NOT the _WINDOWS_ API. It's the CAB SDK. Second, said SDK is not exactly trivial to implement, unlike the current Python zip support. Third, there currently isn't a py module to wrap the CAB SDK but if the OP wants to download the CAB SDK, there are some commandline tools that come with the SDK which can create and extract cabinet files albeit rather unintuitively.
|
|
|
|
 |