## Recommended Posts

I wanted to know how to edit this code to make it loop back to the beginning. Its just a number comparison.

```num1 = 0
num2 = 0

print "Hello, im a number comparison program "

num1 = input("Enter a number ")
num2 = input("Enter another number ")

if (num1 &gt; num2):
print "Your first number is greater"

if (num2 &gt; num1):
print "Your second number is greater"

if (num1 == num2):

here is how i want to finish it in pseudo-code:

``` "Enter another? (Yes or No) &gt; "

if yes loop to beginning
if no print "Goodbye :)"```

any help?

Edited by The Sorrow
##### Share on other sites

while(keep_going) {

if (user says no) {

keep_going = false;

}

}

its in python, :( should have specified

##### Share on other sites

Yea i figured it out.

```num1 = 0
num2 = 0

print "Hello, I'm a number comparison program "
num1 = input("Enter a number&gt; ")
num2 = input("Enter another number&gt; ")

if (num1 &gt; num2):
print "Your first number is greater"

if (num2 &gt; num1):
print "Your second number is greater"

if (num1 == num2):

menuOption = raw_input("Enter another number? (y/n)&gt; ")```

Edited by The Sorrow
##### Share on other sites

`menuOption = raw_input("Enter another number? (y/n)&gt; ")`

is never executed and thus, menuOption cannot be set to "n" by the user.

##### Share on other sites

`menuOption = raw_input("Enter another number? (y/n)&gt; ")`

is never executed and thus, menuOption cannot be set to "n" by the user.

it prompts me if i want to enter another number....so it seems to work. Basically while menuOption is not equal to "n" it'll loop.

Edited by The Sorrow
##### Share on other sites

This is why python is fun (using whitespace as syntax)

```num1 = 0
num2 = 0

print "Hello, I'm a number comparison program "
num1 = input("Enter a number&gt; ")
num2 = input("Enter another number&gt; ")

if (num1 &gt; num2):
print "Your first number is greater"

if (num2 &gt; num1):
print "Your second number is greater"

if (num1 == num2):

menuOption = raw_input("Enter another number? (y/n)&gt; ")```

It needs to be in the while loop. Maybe it is in your editor but it failed to copy/paste correctly.

##### Share on other sites

oh got ya lol. yea, thats how the source is. im taking an intro programming class in college and was ahead so i thought id get more ahead. wowed my instructor and his TAs by using a list array to convert numbers to roman numerals :P

##### Share on other sites

This is why python is fun (using whitespace as syntax)

```num1 = 0
num2 = 0

print "Hello, I'm a number comparison program "
num1 = input("Enter a number&gt; ")
num2 = input("Enter another number&gt; ")

if (num1 &gt; num2):
print "Your first number is greater"

if (num2 &gt; num1):
print "Your second number is greater"

if (num1 == num2):

menuOption = raw_input("Enter another number? (y/n)&gt; ")```

It needs to be in the while loop. Maybe it is in your editor but it failed to copy/paste correctly.

```while(1):
break
exit(0)```

Edited by SomeoneE1se
##### Share on other sites

The break operator is a way of leaving a loop at any point in the loop. In this instance it will have the same effect as using a variable to control the loop condition.

##### Share on other sites

sorry for the double post but this is that roman numeral converter i made today too.

```list = ['I','II','III','IV','V','VI','VII','VIII','IX','X']
number = 0

print "Hello, Im a roman numeral conversion program"

number = input("Enter a number to be converted&gt; ")
if (number &lt; 1):
print "ERROR - Can't convert numbers less than or equal to zero"
if (number &gt; 10):
print "ERROR - Can't convert numbers over 10"
if (number &lt;= 10 and number &gt;= 1):
print list[number - 1]

menuOption = raw_input("Run again y/n &gt; ")
print "Goodbye :)"```

Edited by The Sorrow
##### Share on other sites

```#set vaules
list = ['I','II','III','IV','V','VI','VII','VIII','IX','X']
number = 0

#init
print "Hello, Im a roman numeral conversion program"

while (1):
number = input("Enter a number to be converted&gt; ")
if (number &lt; 1):
print "ERROR - Can't convert numbers less than or equal to zero"
if (number &gt; 10):
print "ERROR - Can't convert numbers over 10"
if (number &lt;= 10 and number &gt;= 1):
print list[number - 1]

menuOption = raw_input("Run again y/n &gt; ")
print "Goodbye :)"
break
#end```

also I would suggest 4 spaces in replacement of tabs when you're working with python.

##### Share on other sites

```#set vaules
list = ['I','II','III','IV','V','VI','VII','VIII','IX','X']
number = 0

#init
print "Hello, Im a roman numeral conversion program"

while (1):
number = input("Enter a number to be converted&gt; ")
if (number &lt; 1):
print "ERROR - Can't convert numbers less than or equal to zero"
if (number &gt; 10):
print "ERROR - Can't convert numbers over 10"
if (number &lt;= 10 and number &gt;= 1):
print list[number - 1]

menuOption = raw_input("Run again y/n &gt; ")
print "Goodbye :)"
break
#end```

also I would suggest 4 spaces in replacement of tabs when you're working with python.

##### Share on other sites

ok so its just good habbit to insert 'break' at the end of a loop

Actually it would be a bad habit to use a break like that. Use of break is generally discouraged. Essentially, a break is very similar to the infamous 'goto' and should be avoided unless necessary.

##### Share on other sites

Actually it would be a bad habit to use a break like that. Use of break is generally discouraged. Essentially, a break is very similar to the infamous 'goto' and should be avoided unless necessary.

in this case you'd be right, but if theres a complicated check required a function+break would be better

code should be easy to read, remember that and you'll do fine

Edited by SomeoneE1se

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account. ×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×