By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,525 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,525 IT Pros & Developers. It's quick & easy.

If swap two lines of the code, would it still give the same output?

P: 1
Here is a mainloop for querying and retrieving stuff.

def mainloop():
s = getinput()
while len(s)>0:
dosomething(s)
s = getinput()
Assume that the getinput function just reads a line of input and puts the contents into s and assume that the dosomething function just prints its string argument.


What happens if the last two lines of the mainloop function were swapped? Would there be any difference?


I tried to get the mainloop() working without swapping the two lines first

def getinput(n):
s = n

def dosomething(s):
print s

def mainloop():
s = getinput()
while len(s)>0:
s = getinput()
do_something(s)

But i seem to get this error:

TypeError: mainloop() takes no arguments (1 given)


Some help would be appreciated
Nov 7 '08 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
Here is a mainloop for querying and retrieving stuff.
Expand|Select|Wrap|Line Numbers
  1. def mainloop():
  2.     s = getinput()
  3.     while len(s)>0:
  4.         dosomething(s)
  5.         s = getinput()
Assume that the getinput function just reads a line of input and puts the contents into s and assume that the dosomething function just prints its string argument.


What happens if the last two lines of the mainloop function were swapped? Would there be any difference?


I tried to get the mainloop() working without swapping the two lines first

Expand|Select|Wrap|Line Numbers
  1. def getinput(n):
  2.     s = n
  3.  
  4. def dosomething(s):
  5.     print s
  6.  
  7. def mainloop():
  8.     s = getinput()
  9.     while len(s)>0:
  10.         s = getinput()        
  11.         do_something(s)
But i seem to get this error:

TypeError: mainloop() takes no arguments (1 given)


Some help would be appreciated
Please use code tags when posting code. The error you report does not appear to have anything to do with your code. Function mainloop() takes no arguments, but when you called it, you must have passed an argument.

If you swapped the last two lines in mainloop(), dosomething() would act upon the second input value of s, which is probably not what you want.
Nov 7 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.