This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def check(numbers): | |
| for i in numbers: | |
| if i == 0: | |
| print("0 is present") | |
| else: | |
| print("0 is not present") | |
| check([1,2,3,4]) ### 0 not present | |
| check([0,1,2]) ## 0 present |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| numbers = [1,2,3,4,5] | |
| fSet = frozenset(numbers) | |
| print('frozen set:', fSet) | |
| >> frozen set: frozenset({1, 2, 3, 4, 5}) | |
| fSet.add('8') | |
| >>AttributeError: 'frozenset' object has no attribute 'add' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import speech_recognition as sr | |
| def command(): | |
| r = sr.Recognizer() | |
| with sr.Microphone() as source: | |
| print("Alexa: Listening...") | |
| audio=r.listen(source) | |
| try: | |
| query = r.recognize_google(audio) | |
| print(f"master:{query}") | |
| return query |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pyttsx3 | |
| engine = pyttsx3.init('sapi5') | |
| voices = engine.getProperty('voices') | |
| engine.setProperty('voice', voices[0].id) | |
| def speak(audio): | |
| engine.say(audio) | |
| engine.runAndWait() | |
| ## speak("Don't Buy Alexa! Build Your Own Using Python") ## uncomment this to test the function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pyttsx3 | |
| import speech_recognition as sr | |
| import wikipedia | |
| import pyjokes | |
| import random | |
| import requests | |
| import datetime | |
| import os |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lst = [1,2,3,4,5,6,7,8,9,10] ## iterable object | |
| def even_or_odd(num): ## Function to check even and odd | |
| if num%2==0: | |
| return "even" | |
| else: | |
| return "odd" | |
| list(map(even_or_odd,lst)) ## using map we are applying the function to each element of the ierable which will check whether the element is even or odd | |
| ----------------------------------------- | |
| ['odd', 'even', 'odd', 'even', 'odd', 'even', 'odd', 'even', 'odd', 'even'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class add: | |
| def __init__(self,a,b): | |
| self.a = a | |
| self.b = b | |
| def add(self): | |
| print(self.a+self.b) | |
| class sub(add): | |
| def __init(self): | |
| super().__init() | |
| super().__init() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from abc import ABC, abstractmethod | |
| class Fruit(ABC): | |
| # abstract method | |
| def noofsides(self): | |
| pass | |
| class Orange(Polygon): | |
| # overriding abstract method | |
| def method(self): | |
| print("I am Juicy") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Computer: | |
| def __init__(self): | |
| self.__maxprice = 800 | |
| def sell(self): | |
| print("Selling Price: {}".format(self.__maxprice)) | |
| def setMaxPrice(self, price): | |
| self.__maxprice = price |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Python is an interpreted, high level and general purpose programming language. | |
| Python's design philosophy emphasizes code readability with its notable use of significant whitespace. | |
| Its language constructs and object oriented approach aim to help programmers write clear, | |
| logical code for small and large-scale projects.[28] | |
| Python is dynamically typed and garbage collected. | |
| It supports multiple programming paradigms, including structured ( particularly procedural ) object oriented, | |
| and functional programming. Python is often described as a "batteries included" language due to its comprehensive standard library. | |
| Python was created in the late 1980s, and first released in 1991, | |
| by Guido van Rossum as a successor to the ABC programming language. Python 2.0, released in 2000, | |
| introduced new features, such as list comprehensions and a garbage collection system with reference counting, |