# Python qiymati o'zgarganligini tekshirish

Agar yangi raqam o'zgarmaydigan bo'lsa oxirgi raqamga (bir xil raqamga) teng bo'lsa, "bir xil raqam" ni bosib chiqarishni xohlayman. Buni qanday qilishim mumkin?

``````from random import randint
x=0
number=(randint(0,9))
while(x<10):
x+= 1
if(number=="""LAST PRINTED VALUE NUMBER"""):
print ("Same number")
else:
print(number)
``````
0
Oldingi raqamni kuzatib boringmi?
qo'shib qo'ydi
Bundan tashqari, loopda `number` ni yangilashingiz kerak.
qo'shib qo'ydi

## 6 javoblar

Siz vaqt oralig'ida so'nggi raqamni tanlashingiz mumkin:

``````x, last = 0, -1
while (x < 10):
number = randint(0, 9)
if (number == last):
print ("Same number")
else:
print("Last number is {0} now it is {1}".format(last,number))
last = number
x += 1
``````

Chiqish:

``````Last number is -1 now it is 1
Last number is 1 now it is 2
Last number is 2 now it is 4
Same number
Last number is 4 now it is 2
Last number is 2 now it is 6
Last number is 6 now it is 7
Same number
Last number is 7 now it is 2
Same number
``````
1
qo'shib qo'ydi

Siz vaqt oralig'ida so'nggi raqamni tanlashingiz mumkin:

``````x, last = 0, -1
while (x < 10):
number = randint(0, 9)
if (number == last):
print ("Same number")
else:
print("Last number is {0} now it is {1}".format(last,number))
last = number
x += 1
``````

Chiqish:

``````Last number is -1 now it is 1
Last number is 1 now it is 2
Last number is 2 now it is 4
Same number
Last number is 4 now it is 2
Last number is 2 now it is 6
Last number is 6 now it is 7
Same number
Last number is 7 now it is 2
Same number
``````
1
qo'shib qo'ydi
``````from random import randint
x = 0
number = -1
while(x < 10):
y = number
number=(randint(0,9))
x+= 1
if(number== y):
print ("Same number")
else:
print(number)
``````
0
qo'shib qo'ydi
qo'shib qo'ydi
``````from random import randint
x = 0
number = -1
while(x < 10):
y = number
number=(randint(0,9))
x+= 1
if(number== y):
print ("Same number")
else:
print(number)
``````
0
qo'shib qo'ydi
qo'shib qo'ydi

Faqat oxirgi birini saqlang:

``````from random import randint
x=0
old = number= randint(0,9)
while(x<10):
x+= 1
if(number==old and x > 0):
print ("Same number")
else:
print(number)
old = number
number = randint(0,9)
``````
0
qo'shib qo'ydi

Faqat oxirgi birini saqlang:

``````from random import randint
x=0
old = number= randint(0,9)
while(x<10):
x+= 1
if(number==old and x > 0):
print ("Same number")
else:
print(number)
old = number
number = randint(0,9)
``````
0
qo'shib qo'ydi Python
372 ishtirokchilar

Bu guruh python dasturlash tilini muhokama qilish uchun. Iltimos, o'zingizni hurmat qiling va faqat dasturlash bo'yicha yozing. Botlar mavzusini @botlarhaqida guruhida muhokama qling! FAQ: @PyFAQ Offtopic: @python_uz_offtopic Python offtopic group !
150 ishtirokchilar

@python_uz gruppasining offtop gruppasi. offtop bo'lsa ham reklama mumkin emas ) Boshqa dasturlash tiliga oid gruppalar @languages_programming