Исходный код: Использование словаря



Download 21,64 Kb.
Sana31.12.2021
Hajmi21,64 Kb.
#204406
Bog'liq
piton misollar


Исходный код: Использование словаря

# Program to count the number of each vowels
# string of vowels

vowels = 'aeiou'
ip_str = 'Hello, have you tried our tutorial section yet?'
# make it suitable for caseless comparisions

ip_str = ip_str.casefold()
# make a dictionary with each vowel a key and value 0

count = {}.fromkeys(vowels,0)
# count the vowels

for char in ip_str:

if char in count:

count[char] += 1
print(count)

Выход

{'o': 5, 'i': 3, 'a': 2, 'e': 5, 'u': 3}


Example 1: Tub sonlar


# Program to check if a number is prime or not
num = 29
# To take input from the user

#num = int(input("Enter a number: "))
# define a flag variable

flag = False
# prime numbers are greater than 1

if num > 1:

# check for factors

for i in range(2, num):

if (num % i) == 0:

# if factor is found, set flag to True

flag = True

# break out of loop

break
# check if flag is True

if flag:

print(num, "is not a prime number")

else:

print(num, "is a prime number")

***********************************************************************
num = 407
# To take input from the user

#num = int(input("Enter a number: "))
# prime numbers are greater than 1

if num > 1:

# check for factors

for i in range(2,num):

if (num % i) == 0:

print(num,"is not a prime number")

print(i,"times",num//i,"is",num)

break

else:

print(num,"is a prime number")



# if input number is less than

# or equal to 1, it is not prime

else:

print(num,"is not a prime number")

# Python program to display all the prime numbers within an interval
lower = 900

upper = 1000
print("Prime numbers between", lower, "and", upper, "are:")
for num in range(lower, upper + 1):

# all prime numbers are greater than 1

if num > 1:

for i in range(2, num):

if (num % i) == 0:

break

else:

print(num)

class Armor:

    

    def __init__(self, armor: float, description: str, level: int = 1):



        self.armor = armor

        self.level = level

        self.description = description

                

    def power(self) -> float:

        return self.armor * self.level

    

armor = Armor(5.2, "Common armor.", 2)



armor.power()

# 10.4


 

print(armor)
Download 21,64 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish