masalalar
Tags: beginners, python, tutorial, github
Published: 2023-02-01 18:11:56

#print funksiyasi chop etish bo'lib nimadir so'z , raqam , shakl va shunga o'xshash narsalarni chiqaradi . 
print("|\\_/|")
print("|qp| /}")
print("|\"^\"` |")
print("||_/=\\\\__|") # bu kodni paytonda yozgandan keyin run qilinganda kuchukcha chiqadi . 

print("\    /\\")
print(" )  ( ')")
print(" (  /  )")
print("  \(__)|") # bunda esa mushukcha chiqadi 

print("Man Abdusalimov Shoxjaxonman ")
print("Ilm hub it kursida oqiyman ")
print("it kursida 4 oydadn buyon oqiyman ")
print("bu kurs manga juda ham yoqadi ")
print("bu sohaga ozim hohlab kirganman ")
print("uzim maktabda informatika va matematika fanlariga qiziqaman")
print("maktabda boshqa fanlarda ham yaxshi oqiyman ")
print("hozir shu yilda choragimda umuman 3 baho yoq ")
print("maqsadim yaxshi pragrammist bo'lish ")# bu yerda men o'zim haqimda ma'lumotni yozib o'tganman bu string tipi . 


print("         /\\")
print( "       /  \\")
print("       / ___\\")
print("      /  { } \\")
print("     /   { }  \\")
print("    |    ---   |")
print("    |----------|")
print("    |          |")
print("    |  _______ |")
print("    |  |  |  | | ")
print("    |  | ? |?| | ")
print("    |  |  |  | | ")
print("    ------------")# bu uy esa mening ijodim . 

print("     _ _ _ _ _ _ _                 _ _ _ _ _ _ _ ")
print("    /             \               /            \ ")
print("   /               \            /               \ ")     
print("  /                 |          |                 \ ")
print("  |                 \         /                   |")
print("  |                  |       |                    |")
print("  |                   \     /                     |")
print("  |                    \   /                      |")
print("   \                    \ /                       /")
print("    |                                            |")
print("     \                                          /")
print("     |                                         |")
print("      \                                       /")
print("       |                                     |")
print("        \                                   /")
print("          \                               /")
print("            \                           /")
print("              \                       /")
print("                \                   /")
print("                  \               /")
print("                    \           /")
print("                      \       /")
print("                        \    /")
print("                         \  /")

print("     _ _ _ _ _ _ _                 _ _ _ _ _ _ _ ")
print("    /             \               /            \ ")
print("   /               \            /               \ ")     
print("  /                 |          |                 \ ")
print("  |                 \         /                   |")
print("  |                  |       |                    |")
print("  |                   \     /                     |")
print("  |                    \   /                      |")
print("   \                    \ /                       /")
print("    |                    /                       |")
print("     \                   /                       /")
print("     |                  /                       |")
print("      \                  \                     /")
print("       |                   \                 |")
print("        \                   /               /")
print("          \                /              /")
print("            \               \            /")
print("              \               \        /")
print("                \             /      /")
print("                  \          /     /")
print("                    \        \   /")
print("                      \      \ /")
print("                        \   //")
print("                         \ //")   # bu ijodlarim ga qanday baho berasiz . ? 


# sharti : salom so'ziga aleykum so'zini qo'shib chiqaring . 
x = "salom"
y = "aleykum"
c=x+y
print(c)

# sharti : Natija degan so'z chiqsin va 10 ga 15 ni qo'shib chiqarsin . 
x= 10
y=15
c=x+y
print("Natija:",c)

# 10 ga 15 ni qo'shib chiqarsin . 
x = 10
y = 15
c = x+y 
print(c)

#payton haqida ma'lumotni chiqarish . 
print("payton bu - dasturlash tili bo'lib . U 1991-yilda guid van Rossum tomonidan yaratilgan.")
print("U eng kerakli dasturlash tillaridan biri ")
print("U eng onson va qulay tillardan biri")

#input bu input qilingan narsani ekranga chiqarish . int
a=input('Birinchi sonni kiriting: ')
b=input('Ikkinchi sonni kiriting: ') # bunda siz sonlarni o'zingiz kiritasiz yoki so'zlarni . 
c=int(a)+int(b) # kiritgan ikkita sonni bir biriga qo'shish . 
print('Natija:', c) natija yozuvidan keyin javobni chiqarish . 

# input stringda . 
a=input('Ismizni kiriting: ')
b=input('yoshizni kiriting: ')
c=str(a)+str(b)
print('Natija:c')

# tushuntirish : str - so'zga , int - sonlar uchun . 


 # input qilinayotganda tipi bilan yozsa bo'ladi bu aniqroq bo'ladi . 
a=int(input('Sonni kiriting:'))
print(a,a,a,a,a)
print(a,'     ', a)
print(a,'     ', a)
print(a,a,a,a,a) # bu yerda a dan to'rt burchak yasaganman . 

a =' salom'
b=12
c='hayr'
print(type(a)) agar yozgan variablesingiz ni tipini bilmoqchi bo'lsangi type funksiyasidan foydalanamiz . 
print(type(b))
print(type(c))

x=5
y=2
x+=5 #x=x+5
print(x)
x/=x/y#x=x/y
print(x)
y-=3 #y=y-3 
print(y) bu qisqaroq ko'rinishda yozish . 

from datetime import datetime

bugun = datetime.now()
print(bugun.strftime("%Y-%m-%D")) # sana ni chiqarib beradi . 


# kocha=bobur
# mahalla=sog'bon
# tuman=bodomzor
# viloyat=samarqand
# e=a+b+c+d
# print(e)

# ism=input("ismingiz nima""  ")
print("assalomu aleykum,"+ism)


ism=input("ismingiz nima?\n>>>")#foydalanuvchi ismini yangi qatordan kiritadi
print("assalomu aleykum,"+ism.title())
#title()bu metodlar deyiladi sozning bosh harfini kichkina yozsak bizga kotta qilib beradi . 

ism=input("ismingiz nima \n>>>")
print("assalomu aleykum,"+ism.upper())#upper=hammasi kotta 

ism=input("ismingiz nima \n>>>")
print("assalomu aleykum,"+ism.lower())#lower=hammasi kichkina

ism=input("ismingiz nima \n>>>")
print("assalomu aleykum,"+ism.capitalize())#capitalize=bosh harfini kotta qilib beradi. 

# variables lardan foydalanib "nexia " " tico " " damas " "ko'rganlar qilar havas " qilib chiqaring
a="''nexia''""   "
b="''tico''""   "
c="''damas'' ""   "
e="ko'rganlar qilar havas""   "
d=a+b+c+e
print(d)

# n ni 4- darajasi 
n=5
input(n*n*n*n)

# a / b ni ekranga chiqar . 
a=22
b=4
input(a/b)

a=125
input(a*a) # a ni kvadrati 
input(a+a+a+a) # 4 a 

print(abs(-5.5))

print(round(5.49))

name='Beau'
print(name) ismni chiqar . 

name='Be\au' # Beu chiqadi . 
print(name) 

name='Be\nau'
print(name) # be pastidan au chiqadi . 

kocha="bobur"
mahalla="sog'bon"
tuman="bodomzor"
viloyat="samarqand"
print  (kocha+"kochasi,"+mahalla+"mahallasi,\n"+tuman+"tumani,"+
viloyat+"viloyati,")

print("quyidagi malumotlarni kiriting")
a=input('kocha:')
b=input('mahalla:')
f=input('tuman:')
d=input('viloyat:')
print  (a+"kochasi,"+b+"mahallasi,\n"+"tumani,"+
d+"viloyati,")


#o'zgaruvchilar - ma'lumot qiymatlrini saqlsh uchun kanteyner stakan
#butun sonlar uchun integer -int!

x=5
y="manzura"# bu faqat tekstlar uchun ishlatiladi string -str
print(x)
print(y)

x=4
x='umid'
print(x) # umid chiqadi . 
#int - bu butun sonlarga 
# float- kasr sonlarga
# string - tekst ga

      
x=int(3)
y=float(2.5)      
z=str(3)
print(x)
print(y)
print(z)

#error -noqonuniy o'zgaruvchilarr xatolik beradi bunday qilib chaqirib bolmaydi
2myvar="John"
my-var="john"
my var='john'

# ko'p qiymatlardan bir nechta o'zgaruvchilarga
# pyton bir qatorda bir nechta o'zgaruvchilrga qiymatlarni belgilash imkonini beradi ;
x,y,z="Orange",'banana',"cherry"
print(x)
print(y)
print(z)
#va bir qatorda bir nechta o'zgaruchilarga bir xil qiymatni belgilashingiz mumkin;

#payton print() funksiyasi ko'pchilik o'zgaruvchilarni chiqarish uchun ushlatildi 
x="payton is awesome"
print(x)

# print () funksiyasi siz vergul bilan ajratilgan bir nechta o'zgaruvchilrni chiqarasiz :
x="payton"
y="is"
z="awesome"
print(x,y,z) # chiqad payton is awesome . 

#bir nechta o'zgaruvchilarni chiqarish uchun + operatoridan ham foydalanish mumkin
#unpack a collection - to'plami.
#agar sizda ro'yxat va kortej va boshqalarda qiymatlar toplami bo'lsa. pyton sizga qiymatlarni o'zgaruvchilrga ajratib olish ijmkonini beradi . bunga qadoqdan chiqarish deyiladi . 

misol uchun : 
ro'yxatdaan o'ting 
fruits=["apple","banana","cherry"]
x,y,z=fruits
print(x)
print(y)
print(z) hammasida fruits chiqadi . 
# tushuntirish  : fruits x y z ga teng biz x y z ni fruits ga tenglayapmiz shuning uchun . 
#raqamlar uchun + bilgisi matematik operator sifatida ishlaydi :

x=5
y=10
print(x+y) # javobi 15 chiqadi . 
#pyton -global variables
#global variables-global o'zgaruvchilar
#junktsiyadan tshqarida yaratilgan o'zgaruvchilar (yuqoridagi barcha misollarda bo'lgani kabi)global o'zgaruvchilar deb nomlanadi 
#global o'zgaruvchilar funksiyalar ichida ham , tshqarisida ham hamma foydalanishi mumkin . 

#misol uchun :
#funksiyadan tashqarida o'zgaruvchi yarating va uni funksiya ichida ishlating

x="Abdullox"
x="Muhammad"
print(x) # bu yerd ham boyagi fruits ga o'xshab yozilgan  . 

y=2023
a=int(input("nechinchi yilsiz:"))
c=y-a
print(c) # yilni aytganda yoshni hisoblab berish . 

def myfunc():
  print(75+1)

myfunc()  # funksiya bilan ishlash . 
                      ma'lumot turlari 

#O'rnatilgan ma'lumotlar turlari 
#dasturlashda ma'lumotlar turi muhim tushunchadir
#O"zgarubchilar har xil turdagi ma'lumotlarni saqlashi mumkin va har xil ishlarni bafarishi mumkin . 

#Payton dasturlsh tilida quyidagi ma'lumot turlari mavjud . 
#Ttext type -string 
# umeric types - integer , float complex
# sequense types -list , tuple , range 
# Mapping type -dict
# set types -set frozenest
# boolean type -bool 
# binary types -bytes ,bytearray , memoryview 
# none type -none type 

# misol uchun :
# x="hello world"#string 
# x=20--int 
# x=20.5--float
# x=1 j -- komplex
# x=["apple","banan","cherry"]--list
# x=("apple","banan","cherry")--tuple
# x=range(6)--range 
# x={"name",:"john",:"age":36}--dict
# x={"name","john",:"age"36}--setk
# frozenset({"apple","banan", "cherry"})
# x=True
# x=b"hello"--bytes 
# x=bytearray (5)--bytearray
# x=mmemoryvew(bytes(5))-memoryview
# x=none--nonetype

# stringa mashq!

x="hello world"
display x:
print(x)
display the data type of x :
print(type(x))

#int ga mahsq!
x=20

display the data type of x :
print(type(x))

#intga mashq!
x=20
y=25
c=x+y
z=c+x
e=z+c
print(e)

#float ga mahsq!
x=20.5

display x:
print(x)

display the data type of x:

print(type(x))


# complex ga mahsq!
x = 1j
display x: 
print(x)
display the data type of x :
print(type(x))
x=9+8j
y=10+4.5j
z=11.2+1.2j
print(type(x))
print(type(y))
print(type(z))

print(x)
print(y)
print(z)

#list ga mashq!
x=["apple","banan","cherry"]
display x :
print(x[2])

#display the data type of x :

print(type(x))
my_list=["jesa","kelly",20,35,75]
print(my_list)
print(type(my_list))


#tuplga mashq!
x=("apple","bananana","cherry")

display x :
print(x[2])

my_tuple=(11,24,56,88,78)
print(my_tuple[2:5])
print(type(my_tuple))
range ga mashq!
x=range(6)#sonlarni tartiblab beradi 

display x :
print(x)
display the data type of x :
print(type(x))
range ga mashq!
x=range(6)

display X :
print(x)
desplay the data type of x :
print(type(x))

#stringga mashq :


x="Hello world"
print(x)
print(type(x))

#intga mashq :
x=30
print(x)
print(type(x))

#floatga mashq :
x=30.5
print(x)
print(type(x))

#complexga mashq :
x=3j
print(x)
print(type(x))

#listga mashq :
x=["apple" , "banan", "cherry"]
print(x)# agar aynan bittasini chiqarmoqchbo'lsangiz print(x[1])mana shunday ko'rinishda yozasiz . Raqamlash 0 dan boshlanadi . 
print(type(x))

#tuple ga mashq :
x=("apple", "banan", "cherry")
print(x) # bu yerda ham aynan bittasini chiqarmoqchi bo'lsangiz tepada aytganimday qilishingiz kerak bo'ladi. 
print(type(x))

#range ga mashq :
x=range(6)
print(x) 
print(type(x))

setga mashq :
x={"apple","banan","cherry"}
display x:
print(x)

display the data type of the x : 
print(type(x))

#frozensetga mashq :
x=frozenset(["apple","banan","cherry"])
display x :
print(x)
print(type(x))

#boolga mashq :
x=True
display x : 
print(x)
print(type(x))

bytesga mashq :
x=b"Hello"
display x :
print(x)
display the data taype of x :
print(type(x))


sample_set={"Yellow","Orange","Black"}
sample_list=["Blue","Green","Red"]
sample_set.update(sample_list)  #update yangilash
print(sample_set)

set1={10,20,30,40,50}
set2={30,40,50,60,70}
print(set1.union(set2)) # qo'shish , uyishish.

set1={10,20,30}
set2={20,40,50}
set1.difference_update(set2)
print(set1)

#memoryview ga mashq :
x=memoryview(bytes(5))
display x :
print(x)
display the data type of x : 
print(type(x)

#ikkita ro'yxatni lug'atga aylantiring 
keys=["ten","twenty","thirty"]
values=[10,20,30]
res_dict=dict(zip(keys,values))
print(res_dict)

#none ga mashq :
x=None
display x :
print(x)
display the data type of x :
print(type(x))

#setting the specific data type -maxsus turini o'rnatish
#Agar siz ma'lumotlar turini belgilamoqche bo'lsangiz, quyidagi konstruktor funksiyalaridan foydalanishingiz mumkin. 

#Misol uchun 
x=str("Hello world")
x=int(20)
x=float(20.5)
x=complex(1j)
x=list(("Apple","Banan","Cherry"))
x=tuple(("Apple","Banan","Cherry"))
x=range(6)
x=dict(name="John",age=36)
x=set(("apple","banan","cherry"))
x=frozenset(("apple","banan","cherry"))
x=bool(5)
x=bytes(5)
x=bytearray(5)
x=memoryview(bytes(5))


#paytonda uchta ma'lumot turi bor :
# int #butun sonlar uchun 
# float #kasr sonlar uchun 
# complex #murakkab sonlar uchun 
x=1 #int
y=2.8 #float
z=3j #complex

#int
#int yoki butun son - bu musbat yoki manfiy , o'nli kasrsiz , cheksiz uzunlikdagi butun sonlar.
#x=1
#y=313548613165
#z=-352556
print(type(x))
print(type(y))
print(type(z))

#float m shuningdek , 10 ning kuchini ko'rsatish uchun "e" bilan ilmiy raqamlar bo'lishi mumkin.
x=35e3
y=12E4
z=-87.7e100

print(type(x))
print(type(y))
print(type(z))

#konvertatsiya turi 
#siz int () , float() va kompleks() usullari yordamida bir turdan boshqasiga o'zgartirishingiz mumkin.
#misol uchun :

#bir turdan ikkinchisega o'tkazish :
x=1 #int 
y=2.8 #float 
z=1j #complex

#convert from int to float :
a=float(x)

# convert from float to int :
b=int(y)
#convert from int to complex :
c=complex(x)
print(a)
print(b)
print(c)


str(input("ismingiz nima ?:"))
int(input("maoshingiz qancha ?:"))
str(input("qaysi kampaniyada ishlaysiz ?:")) # o'zingiz haqida ma'lumot . 


a=int(input("birinchi sonni kiriting :"))
b=int(input("ikkinchi sonni kiriting :"))
c=a*b
print(print("natija:",c))# kara kara jadavali . 


print("element at odd -index positions fromarks=float(input("enter marks:"))
print("\n")
print("student marks:",marks)
print("type is :",type(marks))# kasr ko'rinishida yozing . 

list1=[1,3,5,7,11,13,17,19,23,31,41]
list2=[2,4,6,8,10,12,14,16,18,20,22]
print("toq sonlar:",list1[0:7])
print("juft sonlar:",list2[0:7])


list1=[1,3,5,7,11,13,17,19,23,31,41]
list2=[2,4,6,8,10,12,14,16,18,20,22]
res=list()
odd_elements=list1[1::2]m list one ")
print(odd_elements)

even_elements=list2[0::2]
print("element at even -index positions from list two")
print(even_elements)

print("printing final third list")
res.extend(odd_elements)
res.extend(even_elements)
print(res)

# solution1
#revers()- bu fundsiy biza kiritgan sonlarnni teskarisiga ugirib beradi.
list1=[100,200,300,400,500]
list1.reverse() #reverse teskarisiga qilish
print(list1)

# solution2
#-1 salbiy kesish dan foydalanish shunda biza kiritgan sonlarnni teskarisiga ugirib beradi va edranga chiqarib beradi .
list1=[300,400,500,600,700]
list1=list1[::-1]
print(list1)

list1=(300,400,500,600,700)
list1=list1[::-1]
print(list1)

tuple1=("orange",[10,20,30],[5,15,25])
print(tuple1)
print(tuple1[0])
print(tuple1[1])
print(tuple1[2])
print(tuple1[1][1])


tuple1=(11,22,33,44,55,66)
print(tuple1[3])
print(tuple1[4])

print(tuple1[3])
list1.reverse()
print(list1[3::-1])
print(tuple(2))