473,508 Members | 2,509 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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
1 1075
bvdet
2,851 Recognized Expert Moderator Specialist
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

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

Similar topics

50
17278
by: Steve | last post by:
How do you rewrite the swap function without using a tmp variable in the swap function???? int main() { int x = 3; int y = 5; // Passing by reference
4
548
by: Simone Battagliero | last post by:
I wrote a program which inserts and finds elements in an hash table. Each element of the table is a dinamic list, which holds all elements having the same hash value (calculated by an int...
21
16825
by: Abhishek Jha | last post by:
hello all, this has been an interesting topic since long. you can swap two numbers (say a and b) using temp(as third variable). you can also swap without using third variable.likeThis was also...
14
5463
by: pras.vaidya | last post by:
hi, please help me with this problem : - how to swap two addresses .For eg variable i is located at 2000 and j at 3000 . Now i call swap function . Result should be that i should be now having...
18
5089
by: Joe Lester | last post by:
This thread was renamed. It used to be: "shared_buffers Question". The old thread kind of died out. I'm hoping to get some more direction by rephrasing the problem, along with some extra...
19
7128
by: Krishanu Debnath | last post by:
Hello, I have a call to hash_map::clear() function which takes long time. someClass::someFunction() { // typedef hash_map<name_id, uintMp; // Mp p; // assuming proper namespace, hash...
2
3023
by: lavender | last post by:
C programming Below is my question and the code. Write a program that will swap two values in an array. If the swap is successfull, the program will display the updated list. If it contains...
22
2026
by: Pramod | last post by:
Hello to all of you, basically i want a program how to swap value...i know 2 method 1st --- temp=a; a=b; b=temp; 2nd---- a=a+b; b=a-b; a=a-b;
25
3736
by: indrawati.yahya | last post by:
OK, before you all stab me with your OT pitchfork, I just want to mention that this question is indeed related to c.l.c++. My question is, does the well-known method to swap two integers produce...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.