|
-savol: Raqamlar ro'yhati berilgan, agar ro'yhatning birinchi va oxirgi raqamlari bir xil bo'lsa, True ni qaytaring
|
səhifə | 2/2 | tarix | 11.11.2022 | ölçüsü | 20,32 Kb. | | #119311 |
| PYTHONDA BAJARISH UCHUN 5 TA MASALA3-savol: Raqamlar ro'yhati berilgan, agar ro'yhatning birinchi va oxirgi raqamlari bir xil bo'lsa, True ni qaytaring
ro'yhat [10, 20, 30, 40, 10]
natija True
ro'yhat [10, 20, 30, 40, 50]
natija False
|
Javobni ko'rish...
4-savol: Raqamlar ro'yhati berilgan, ulardan faqat 5 ga bo'linadiganlarini tanlab yozib chiqing.
Ro'yhat [10, 20, 33, 46, 55]
5 ga bo'linadiganlari
10
20
55
|
Javobni ko'rish...
5-savol: Quyidagicha natija chiqaruvchi kod yozing:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
|
Javobni ko'rish...
#1-misol
def multiplication_or_sum(num1, num2):
product = num1 * num2
if product <= 1000:
return product
else:
return num1 + num2
number1 = 20
number2 = 30
print("\n")
result = multiplication_or_sum(number1, number2)
print("Natija: ", result)
------------------------------------
#2-misol
def sumNum(num):
previousNum = 0
for i in range(num):
sum = previousNum + i
print("Hozirgi raqam", i, "Oldingi raqam", previousNum," Yig'indi: ", sum)
previousNum = i
print("range(10) dagi oldingi va hozirgi raqamlari yig'indisi")
sumNum(10)
------------------------------------
#3-misol
def isFirst_And_Last_Same(numberList):
print("Ro'yhat ", numberList)
firstElement = numberList[0]
lastElement = numberList[-1]
if (firstElement == lastElement):
return True
else:
return False
numList = [10, 20, 30, 40, 10]
print("natija ", isFirst_And_Last_Same(numList))
----------------------------------------
#4-misol
def findDivisible(numberList):
print("Ro'yhat ", numberList)
print("5 ga bo'linadiganlari ")
for num in numberList:
if (num % 5 == 0):
print(num)
numList = [10, 20, 33, 46, 55]
findDivisible(numList)
------------------------------------
#5-misol
for num in range(10):
for i in range(num):
print (num, end=" ") #raqamni chop etish
# har bir qatordan so'ng bo'shliq tashlash
print("\n")
Dostları ilə paylaş: |
|
|