Skip to content

Instantly share code, notes, and snippets.

@alipbudiman
Last active March 9, 2022 15:49
Show Gist options
  • Save alipbudiman/53d41f056c9d8a6299daa4f72ecac5f9 to your computer and use it in GitHub Desktop.
Save alipbudiman/53d41f056c9d8a6299daa4f72ecac5f9 to your computer and use it in GitHub Desktop.
cek bilangan konsekutif di python3
#konsekutif
p = str(input("masukan bilangan: "))
ls = []
stat = 'konsekutif'
stat2 = True
xi = p.isnumeric()
if xi == True:
for x in p:
ls.append(int(x))
inext = None
for i in ls:
if inext == None:
inext = i
else:
if i - inext != 1 and i - inext != -1:
stat = 'non-konsekutif'
stat2 = False
break
else:
inext = None
print(stat)
print(stat2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment