← Back to Community
##### Hey everyone
Profile icon
FARHEENPALAGIRI

Hello everyone. How are you? I'm back, so you're probably annoyed. So, anyways, I was writing this code, and I'm not sure how to do something. Help me out, please?

So in this code I have to get a series of numbers and print the first pair of consecutive numbers that share the same sign (+/-). And if there are no consecutive numbers that share the same sign, I have to print 0. So, I've managed to do the first part with a for loop, but I'm clueless on how to do the second part. Can you guys give me some advice please? Thanks!

Here's the code:

a = [int(s) for s in input().split()]
w = []
e = 1

for i in range(len(a)):
if a[e] > 0 and a[e-1] > 0 or a[e] < 0 and a[e-1] < 0:
print(a[e-1] , a[e])
break
else:
e += 1
continue

Answered by ArchieMaclean [earned 5 cycles]
Voters
Profile icon
FARHEENPALAGIRI
hotnewtop
Profile icon
ArchieMaclean
```.css-19sk4h4{position:relative;}.css-1bu6gr6{-webkit-align-items:stretch;-webkit-box-align:stretch;-ms-flex-align:stretch;align-items:stretch;border-width:0;border-style:solid;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-basis:auto;-ms-flex-preferred-size:auto;flex-basis:auto;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;outline:none;min-height:0;min-width:0;position:relative;}.css-1n2m10r{padding:var(--space-8);border-radius:var(--border-radius-4);background-color:var(--background-higher);}.css-1hwur6u{-webkit-align-items:stretch;-webkit-box-align:stretch;-ms-flex-align:stretch;align-items:stretch;border-width:0;border-style:solid;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-basis:auto;-ms-flex-preferred-size:auto;flex-basis:auto;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;outline:none;min-height:0;min-width:0;padding:var(--space-8);border-radius:var(--border-radius-4);background-color:var(--background-higher);}.css-1ubbl1f{padding:var(--space-4);padding-left:var(--space-4);padding-right:var(--space-2);font-family:var(--font-family-code);font-size:14px;line-height:var(--line-height-small);overflow-x:auto;word-break:break-word;white-space:break-spaces;overflow-wrap:anywhere;}```if (a[e]+1)==a[e+1] or (a[e]-1)==a[e+1]:
print(a[e]+" "+a[e+1]``````

Please upvote if this helps :)

Profile icon
Scoder12

What is the variable `e` for? couldn't you just use `i`? As for the solution, just set a variable, such as `done` to `False` at the beginning of your program and set it to true if you find a pair. If the variable is still false when you are done with the loop, print `0`.

I am repl.it helper. If this is a good answer, please upvote!

Profile icon
FARHEENPALAGIRI

Thanks a lot!