Stupid n00b Loop question

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

Stupid n00b Loop question

Postby Buzzrightear » Thu Jun 13, 2013 9:41 am

Hi, I am well aware that this is a 'wrong' question on many levels but please do bear with me. I'm working on a locked-down school system so am having to use an online Python IDE, which I think due to the locked-down nature of the school system can import the time module, but can't execute the time.sleep() method. As a result, I can't put a delay into a little zombie text game that I wanted to get some students to do (code below). I thought that a cack-handed solution might be to create a sleep function from a while loop executing a large number of times, in order to make it seem like there was a pause in the game. However, although the code executes successfully, the pause doesn't actually happen at the right moment. I would expect a pause whenever the sleep2() function is invoked, but instead, the print output lines that are after the sleep2() function in the code tend to be executed before the pause. I know this is all so, so wrong, but I'd appreciate an explanation of why the pause doesn't occur when I expect it to. Don't worry, I will not be teaching this to students!


Code: Select all
def sleep2():
   i=1
   while i < 1000000:
      i += 1
print "welcome to Zombieland"
print "Keep away from the Zombies"
character=raw_input("Type a name for character here >")
print "Turn away now %s, YOU HAVE BEEN WARNED!" %(character)
sleep2()
print "Jack Swan: AAAAAAAAGGGGGHHHHHH!!!........RUUUUUUUUUUNNNNNNNN"
sleep2()
print ".............."
sleep2()
print "Jack Swan: There are at least 15 zombies heading our way!"
Buzzrightear
 
Posts: 1
Joined: Thu Jun 13, 2013 8:37 am

Re: Stupid n00b Loop question

Postby Mekire » Thu Jun 13, 2013 10:17 am

Questionability of this aside, the delays occurred exactly where I expected them to (save for the fact I needed to add an additional zero to make the delay longer). I suspect this has more to do with you using an online python interpreter. Perhaps try Portable Python (running off USB) instead.

-Mek
User avatar
Mekire
 
Posts: 1033
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 4 guests