0% found this document useful (0 votes)
17 views6 pages

Bismillah

The document contains various Python code snippets demonstrating user input handling, prime number generation, error handling, geometric calculations, list manipulations, and algorithm implementations for common problems like two-sum and palindrome checking. It also includes class definitions showcasing inheritance and method overriding. Overall, it serves as a collection of programming exercises and examples in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views6 pages

Bismillah

The document contains various Python code snippets demonstrating user input handling, prime number generation, error handling, geometric calculations, list manipulations, and algorithm implementations for common problems like two-sum and palindrome checking. It also includes class definitions showcasing inheritance and method overriding. Overall, it serves as a collection of programming exercises and examples in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

# username = input("Enter your username: ")

# if username != "umidjon18":
# print("Username not found:", username)
# else:
# password = input("Enter your password: ")
# if password != "mytg":
# print("Password is incorrect !!!")
# else:
# print("Hello Mr", "Umidjon")

###################################################################################
##########
# print("Hello, I'm a function which is responsible to print prime numbers in a
range")

# start = int(input("Enter the start of the range: "))


# stop = int(input("Enter the end of the range: "))
# primeNumbers = []
# for number in range(start, stop + 1):
# if number > 1:
# isPrime = True
# for i in range(2, number):
# if number % i == 0:
# isPrime = False
# break
# if isPrime:
# primeNumbers.append(number)
# if len(primeNumbers) == 0:
# print(f"There is no any prime number in a range of {start} - {stop}")
# else:
# print("Here is the list of prime numbers in it:", primeNumbers)
###################################################################################
##########
# numberAsString = input("Enter a number: ")
# try:
# number = int(numberAsString)
# print(f"Good job: {number}")
# except:
# print("Not a number")
###################################################################################
##########
# width = int(input('Enter the width: '))
# height = int(input('Enter the height: '))
# hypotenuse = (width**2+height**2)**.5
# print(f'Hypotenuse is : {round(hypotenuse, 2)}')
###################################################################################
##########
# numbers_list = [1,2,3,4,5,6,7,8,9,10]
# print(numbers_list[7::-2])
# a_list = [1,2,3,4,5]
# for item in a_list:
# if item ==2:
# print(f'the value is {item}')
# else:
# print(f'the value is not 2')
# if item ==5:
# count = 0
# while count<6:
# print('last item')
# count+=1
###################################################################################
##########

# a_list = [1,2,3,4,5,6,7,8,9,10]
# for index, value in enumerate(a_list, start=5):
# print(index, value)
# from typing import List

# def twoSum(nums: List[int], target: int) -> List[int]:


# n = len(nums)
# for i in range(n-1):
# for j in range(i+1, n):
# if(nums[i]+nums[j]==target):
# return [i, j]
# return []

# print(twoSum(nums=[2, 11, 15, 7], target=9))


###################################################################################
##########

# def isPalindrome(self, x: int) -> bool:


# if x <= 0 or x % 10 == 0:
# return False
# reversedHalf = 0
# while x > reversedHalf:
# reversedHalf = reversedHalf * 10 + x % 10
# x //= 10
# return x == reversedHalf or x == reversedHalf // 10

# print(isPalindrome(any, 1221))
###################################################################################
##########
# romanNumbers = {
# "I": 1,
# "V": 5,
# "X": 10,
# "L": 50,
# "C": 100,
# "D": 500,
# "M": 1000,
# "IV": 4,
# "IX": 9,
# "XL": 40,
# "XC": 90,
# "CD": 400,
# "CM": 900,
# }

# def romanToInt(self, s: str) -> int:


# sum = 0
# print(len(s))
# for i in range(len(s), 0):
# print(i)
# sum += romanNumbers[i]
# return sum

# print(romanToInt(any, "MCMXCIV"))

# Input: s = "MCMXCIV"
# Output: 1994
###################################################################################
##########

# from typing import List

# def longestCommonPrefix(self, strs: List[str]) -> str:


# prefix = min(strs)
# minLength = len(prefix)
# check = False
# while minLength > 0:
# for str in strs:
# if str[:minLength] == prefix:
# check = True
# else:
# check = False
# minLength -= 1
# prefix = prefix[:minLength]
# break
# if check:
# return prefix
# return ""

# print(longestCommonPrefix(any, ["flower", "flow", "flight"]))


# print(longestCommonPrefix(any, ["dog","racecar","car"]))
# print(not None)
###################################################################################
##########

# def isValid(self, s: str) -> bool:


# opens = ["(", "[", "{"]
# couples = {")": "(", "]": "[", "}": "{"}
# collector = []
# for item in s:
# if item in opens:
# collector.append(item)
# else:
# if collector and couples[item] != collector[-1]:
# return False
# elif collector:
# collector.pop()
# else:
# return False
# return len(collector)==0

# print(isValid(any, "()[]{}"))
###################################################################################
##########
# from typing import List

# def removeDuplicates(self, nums: List[int]) -> int:


# keeper = 1
# for i in range(1, len(nums)):
# if nums[i]!=nums[i-1]:
# nums[keeper] = nums[i]
# keeper+=1
# return keeper

# print(removeDuplicates(any, [0, 0, 1, 1, 1, 2, 2, 3, 3, 4]))


###################################################################################
##########

# from typing import List

# def removeElement(self, nums: List[int], val: int) -> int:


# keeper = 0
# for i in range(0, len(nums)):
# if nums[i] != val:
# nums[keeper] = nums[i]
# keeper += 1
# return keeper

# print(removeElement(any, [0, 1, 2, 2, 3, 0, 4, 2], 2))


###################################################################################
##########

# def strStr(self, haystack: str, needle: str) -> int:


# if len(haystack) < len(needle):
# return -1
# elif haystack == needle:
# return 0
# firstIndex = -1
# needleIndex = 0
# for i in range(0, len(haystack)):
# if len(needle) == needleIndex:
# break
# if needleIndex != 0 and haystack[i] == needle[-1]:
# firstIndex = i - len(needle) + 1
# if haystack[i] == needle[needleIndex]:
# if needleIndex == 0:
# firstIndex = i
# needleIndex += 1
# else:
# needleIndex = 0
# firstIndex = -1
# return firstIndex

# print(strStr(any, "abc", "c"))

# my_list = [f'{i*i}{j}' for i in range(0, 20) for j in ('a','b','c') if j == 'c']


# print(my_list )
# class Human:
# def __init__(self, name, age):
# self.name = name
# self.age = age

# def fight():
# print("Go fighting")

# class HumanTwo:
# def __init__(self, name, country):
# self.name = name
# self.country = country

# class Person(Human, HumanTwo):


# def __init__(self, name, age):
# super().__init__(name, age)

# def fight():
# print("Fighting implemented")

# humanbeing = Person("Umidjon", age=21)

# print(isinstance(humanbeing, HumanTwo))

# class MonsterAncector:

# def attack(self):
# print(f"attack, damage: {self.damage}")

# class Monster(MonsterAncector):
# def __init__(self, health, damage):
# self.health = health
# self.damage = damage

# def __str__(self):
# return f"a monster with {self.health} hp"

# class OtherMonster(MonsterAncector):
# def __init__(self, health):
# self.health = health

# monster_instance = OtherMonster(100)
# monster_instance.attack()
# print(monster_instance)

class Person:
def __init__(self, name):
self._name = name

def _say_name(self):
print("His name is", self._name)

one = Person("Umidjon")
print(one._name)
one._say_name()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy