├── .idea ├── .gitignore ├── vcs.xml ├── misc.xml ├── inspectionProfiles │ └── profiles_settings.xml ├── modules.xml └── PythonProject.iml ├── Program1.py ├── Program42.py ├── Program6.py ├── Program23.py ├── Program35.py ├── Program40.py ├── Program8.py ├── Program39.py ├── Program10.py ├── Program14.py ├── Program33.py ├── Program37.py ├── Program5.py ├── Program11.py ├── Program24.py ├── Program7.py ├── Program21.py ├── Program2.py ├── Program32.py ├── Program12.py ├── Program18.py ├── Program19.py ├── Program38.py ├── Program27.py ├── Program22.py ├── Program34.py ├── Program45.py ├── Program13.py ├── Program16.py ├── Program28.py ├── Program36.py ├── Program17.py ├── Program41.py ├── Program4.py ├── Program25.py ├── Program15.py ├── Program26.py ├── Program31.py ├── Program29.py ├── Program30.py ├── Program3.py ├── Program43.py ├── Program44.py └── Program20.py /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /Program1.py: -------------------------------------------------------------------------------- 1 | print(105) 2 | print(10.5) 3 | print("Welcome to Python ! This is Anisul Islam") -------------------------------------------------------------------------------- /Program42.py: -------------------------------------------------------------------------------- 1 | # How to write in a file (python) 2 | 3 | file = open("student.txt","a") 4 | 5 | 6 | file.write("\nRobiul Islam - Physics") 7 | 8 | 9 | file.close() -------------------------------------------------------------------------------- /Program6.py: -------------------------------------------------------------------------------- 1 | # type casting 2 | num1 = input("Enter First Number : ") 3 | num2 = int(input("Enter Second Number : ")) 4 | sum = int(num1) + num2 5 | print("Sum is : ", sum) -------------------------------------------------------------------------------- /Program23.py: -------------------------------------------------------------------------------- 1 | # series program 2 | # 1 + 2 + 3 + ... + n 3 | n = int(input("Enter the last number : ")) 4 | sum = 0 5 | for x in range(1, n+1, 1): 6 | sum = sum + x 7 | print("sum = ", sum) -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Program35.py: -------------------------------------------------------------------------------- 1 | # debugging 2 | def addition(*numbers): 3 | sum = 0 4 | for x in numbers: 5 | sum = sum + x 6 | return sum 7 | 8 | 9 | print(addition(10,20)) 10 | print(addition(10,20, 30)) 11 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Program40.py: -------------------------------------------------------------------------------- 1 | # Recursion -> calling a function itself. 2 important things -> recursive call, base case for stopping 2 | def fact(n): 3 | if n == 1: 4 | return 1 5 | 6 | return n * fact(n-1) 7 | 8 | 9 | print(fact(5)) -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /Program8.py: -------------------------------------------------------------------------------- 1 | # Math Related Library functions 2 | from math import * 3 | print(max(5,3)) 4 | print(min(5,3)) 5 | print(pow(5,3)) 6 | print(sqrt(25)) 7 | print(round(5.3)) 8 | print(round(5.8)) 9 | print(floor(5.3)) 10 | print(ceil(5.3)) 11 | -------------------------------------------------------------------------------- /Program39.py: -------------------------------------------------------------------------------- 1 | # Zip Function 2 | roll = [101,102,103] 3 | name = ["Anisul Islam", "Rabeya Begum", "Linkon Talukdar"] 4 | # (roll,name) 5 | # combine 2 list and make one using zip function 6 | print(list(zip(roll,name))) 7 | print(list(zip(roll,name,"ABC"))) -------------------------------------------------------------------------------- /Program10.py: -------------------------------------------------------------------------------- 1 | # Relational operators - >,<,>=,<=, ==, != and Boolean data types -> True / False 2 | 3 | print(20>10) 4 | print(20>=10) 5 | print(20>=20) 6 | 7 | print(20<10) 8 | print(20<=10) 9 | print(20<=20) 10 | 11 | print(20==20) 12 | print(20!=20) -------------------------------------------------------------------------------- /Program14.py: -------------------------------------------------------------------------------- 1 | # ternary operator 2 | num1 = int(input("Enter first number : ")) 3 | num2 = int(input("Enter second number : ")) 4 | ''' 5 | if num1 > num2: 6 | print(num1) 7 | else: 8 | print(num2) 9 | ''' 10 | print(num1 if num1 > num2 else num2) -------------------------------------------------------------------------------- /Program33.py: -------------------------------------------------------------------------------- 1 | # Returning value from function 2 | 3 | 4 | def add(a, b): 5 | return a + b 6 | 7 | 8 | def largeNumber(a,b): 9 | return a if a > b else b 10 | 11 | 12 | maximum = largeNumber 13 | result = add(10,20) 14 | print(result) 15 | print(maximum(20,30)) -------------------------------------------------------------------------------- /Program37.py: -------------------------------------------------------------------------------- 1 | # map function -> works with iterable object (list) 2 | 3 | numbers = [1,2,3,4,5] 4 | 5 | 6 | def square(a): 7 | return a*a 8 | 9 | 10 | result = list(map(square, numbers)) 11 | print(result) 12 | 13 | 14 | result = list(filter(lambda x: x % 2 == 0, numbers)) 15 | print(result) -------------------------------------------------------------------------------- /Program5.py: -------------------------------------------------------------------------------- 1 | # Getting User input 2 | 3 | name = input("Enter your Name : ") 4 | age = input("Enter your Age : ") 5 | cgpa = input("Enter your CGPA : ") 6 | 7 | print("Student Information") 8 | print("---------------------") 9 | print("Name : "+ name) 10 | print("Age : "+ age) 11 | print("CGPA : "+ cgpa) -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Program11.py: -------------------------------------------------------------------------------- 1 | # conditional statement - > if, else statement 2 | 3 | # pass/fail program 4 | marks = int(input("Enter your marks : ")) 5 | if marks >= 33: 6 | print("Pass") 7 | else: 8 | print("Fail") 9 | 10 | # even/odd program 11 | num = int(input("Enter a number : ")) 12 | if num % 2 == 0: 13 | print("Even") 14 | else: 15 | print("Odd") -------------------------------------------------------------------------------- /Program24.py: -------------------------------------------------------------------------------- 1 | # pattern related program 2 | ''' 3 | n = 4 4 | * 5 | ** 6 | *** 7 | **** 8 | ''' 9 | 10 | n = int(input("Enter n = ")) 11 | for x in range(1, n+1, 1): 12 | print(x*"*") 13 | 14 | ''' 15 | n = 4 16 | * 17 | *** 18 | ***** 19 | ******* 20 | ''' 21 | n = int(input("Enter n = ")) 22 | for x in range(1, n+1, 1): 23 | print((2*x-1)*"*") -------------------------------------------------------------------------------- /Program7.py: -------------------------------------------------------------------------------- 1 | # Area of a shape 2 | 3 | # Area of triangle 4 | base = float(input("Enter base = ")) 5 | height = float(input("Enter height = ")) 6 | area = 0.5 * base * height 7 | print("Area of triangle = ", area) 8 | 9 | # Area of circle 10 | radius = float(input("Enter radius = ")) 11 | area = 3.1416 * radius * radius 12 | print("Area of circle = ", area) -------------------------------------------------------------------------------- /Program21.py: -------------------------------------------------------------------------------- 1 | # range function in python 2 | # range will generated a set of numbers 3 | numbers = list(range(10)) 4 | print(numbers) 5 | print(numbers[2]) 6 | 7 | # starting and end point can be set 8 | numbers = list(range(5, 11)) 9 | print(numbers) 10 | 11 | # starting, end point and interval can be set 12 | numbers = list(range(2, 100, 2)) 13 | print(numbers) -------------------------------------------------------------------------------- /Program2.py: -------------------------------------------------------------------------------- 1 | # This is a single line comment 2 | # Backslash characters and comments 3 | ''' 4 | This 5 | is an 6 | example of multiple line comment 7 | 8 | ''' 9 | # print("Name : Anisul Islam") 10 | # print("Address : Sylhet, Bangladesh") 11 | # print("01710444700") 12 | print("Name : Anisul Islam \nAddress : Sylhet, Bangladesh\n01710444700") 13 | print("1\t2") -------------------------------------------------------------------------------- /.idea/PythonProject.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Program32.py: -------------------------------------------------------------------------------- 1 | # introduction to function 2 | 3 | 4 | def add1(a, b): 5 | sum = a + b 6 | print(sum) 7 | 8 | 9 | def add2(a, b, c): 10 | sum = a + b + c 11 | print(sum) 12 | 13 | 14 | def sub(a, b): 15 | result = a - b 16 | print(result) 17 | 18 | 19 | def message(): 20 | print("hello everyone") 21 | 22 | 23 | add1(10, 20) 24 | add2(10, 20, 30) 25 | sub(20, 10) 26 | message() -------------------------------------------------------------------------------- /Program12.py: -------------------------------------------------------------------------------- 1 | # conditional statement - > if, elif, else statement 2 | # Letter Grade program 3 | marks = int(input("Enter your marks : ")) 4 | if marks >= 80: 5 | print("A+") 6 | elif marks >= 70: 7 | print("A") 8 | elif marks >= 60: 9 | print("A-") 10 | elif marks >= 50: 11 | print("B") 12 | elif marks >= 40: 13 | print("C") 14 | elif marks >= 33: 15 | print("D") 16 | else: 17 | print("Fail") -------------------------------------------------------------------------------- /Program18.py: -------------------------------------------------------------------------------- 1 | # sum of n numbers using while loop 2 | # 1 + 2 + 3 + ... + n 3 | sum = 0 4 | i = 1 5 | n = int(input("Enter the last number : ")) 6 | while i <= n: 7 | sum = sum + i 8 | i = i + 1 9 | print("sum = ", sum) 10 | 11 | 12 | # 2 + 4 + 6 + ... + n 13 | sum = 0 14 | i = 2 15 | n = int(input("Enter the last number : ")) 16 | while i <= n: 17 | sum = sum + i 18 | i = i + 2 19 | print("sum = ", sum) -------------------------------------------------------------------------------- /Program19.py: -------------------------------------------------------------------------------- 1 | # break and continue keyword 2 | 3 | # break program 4 | print("Break program : ", end="") 5 | i = 1 6 | while i <= 100: 7 | if i == 20: 8 | break 9 | print(i, end=" ") 10 | i = i + 1 11 | 12 | ''' 13 | # continue program 14 | print("Continue program : ", end="") 15 | i = 1 16 | while i <= 100: 17 | if i == 20: 18 | continue 19 | print(i, end=" ") 20 | i = i + 1 21 | ''' 22 | -------------------------------------------------------------------------------- /Program38.py: -------------------------------------------------------------------------------- 1 | # List comprehensions 2 | 3 | # finding square without using comprehension list 4 | num = [1,2,3,4,5] 5 | result = list(map(lambda x: x*x, num)) 6 | print(result) 7 | 8 | # finding square using comprehension list 9 | # [expression for item in list] 10 | result2 = [x*x for x in num] 11 | print(result2) 12 | 13 | # result3 = list(filter(lambda x : x%2==0, num)) 14 | result3 = [x for x in num if x%2==0] 15 | print(result3) -------------------------------------------------------------------------------- /Program27.py: -------------------------------------------------------------------------------- 1 | # Matrix is a 2 dimensional array or list 2 | A = [ 3 | [1, 2, 3], 4 | [4, 5, 6] 5 | ] 6 | 7 | # printing a specific element of a matrix 8 | print(A[0][1]) 9 | 10 | # setting value of a matrix element 11 | A[0] [1] = 20 12 | 13 | # printing all the rows of a matrix 14 | for row in A: 15 | print(row) 16 | 17 | # printing each item of a matrix separately 18 | for row in A: 19 | for col in row: 20 | print(col) -------------------------------------------------------------------------------- /Program22.py: -------------------------------------------------------------------------------- 1 | # Loop - for loop 2 | ''' 3 | numbers = [10,20,30,40,50,60,70,80] 4 | print(numbers) 5 | i = 0 6 | while i < len(numbers): 7 | print(numbers[i]) 8 | i = i + 1 9 | print("End") 10 | ''' 11 | 12 | # printing all the elements using for loop 13 | numbers = [10,20,30,40,50,60,70,80] 14 | for x in numbers: 15 | print(x) 16 | 17 | # finding the sum of all numbers 18 | sum = 0 19 | for x in numbers: 20 | sum = sum + x 21 | print("sum is : ", sum) 22 | 23 | -------------------------------------------------------------------------------- /Program34.py: -------------------------------------------------------------------------------- 1 | # xargs -> receive any number of parameters -> acts like tuples 2 | def student(*details): 3 | print(details) 4 | print(details[1]) 5 | 6 | 7 | student(101, "Anisul Islam") 8 | student(101, "Rokibul Islam", 3.92) 9 | 10 | # xxargs -> receive any number of parameters -> acts like dictionaries -> key, value 11 | def studentDetails(**details): 12 | print(details) 13 | print(details["id"]) 14 | 15 | 16 | studentDetails(id= 101,Name = "Anisul Islam") -------------------------------------------------------------------------------- /Program45.py: -------------------------------------------------------------------------------- 1 | # swapping -> exchanging values of 2 variables 2 | a = 20 3 | b = 10 4 | print(f"Before swapping a = {a}, b = {b}") 5 | 6 | # swapping using extra variable 7 | print("swapping using extra variable.", end=" ") 8 | temp = a 9 | a = b 10 | b = temp 11 | print(f"After swapping a = {a}, b = {b}") 12 | 13 | # swapping without using extra variable 14 | print("swapping without using extra variable.", end=" ") 15 | a, b = b, a 16 | print(f"After swapping a = {a}, b = {b}") -------------------------------------------------------------------------------- /Program13.py: -------------------------------------------------------------------------------- 1 | # Inner if statement 2 | num1 = int(input("Enter first number : ")) 3 | num2 = int(input("Enter second number : ")) 4 | num3 = int(input("Enter third number : ")) 5 | 6 | if num1 > num2: 7 | if num1 > num3: 8 | print("Large Number : ", num1) 9 | else: 10 | print("Large Number : ", num3) 11 | 12 | if num2 > num1: 13 | if num2 > num3: 14 | print("Large Number : ", num2) 15 | else: 16 | print("Large Number : ", num3) 17 | -------------------------------------------------------------------------------- /Program16.py: -------------------------------------------------------------------------------- 1 | # Letter Grade program using logical operator 2 | # short circuit evaluation 3 | marks = int(input("Enter your marks : ")) 4 | if marks > 100 or marks < 0: 5 | print("Invalid marks") 6 | elif 80 <= marks <= 100: 7 | print("A+") 8 | elif marks >= 70: 9 | print("A") 10 | elif marks >= 60: 11 | print("A-") 12 | elif marks >= 50: 13 | print("B") 14 | elif marks >= 40: 15 | print("C") 16 | elif marks >= 33: 17 | print("D") 18 | else: 19 | print("Fail") -------------------------------------------------------------------------------- /Program28.py: -------------------------------------------------------------------------------- 1 | # Dictionaries -> key, value 2 | # name -anisul islam 3 | # email - anisul2010s@yahoo.co.uk 4 | # word - meaning 5 | 6 | studentId = { 7 | # "101" : "Anisul Islam", 8 | # "102": "Junaed Ahmed", 9 | # "103": "Rabeya Begum", 10 | 101: "Anisul Islam", 11 | 102: "Junaed Ahmed", 12 | 103: "Rabeya Begum", 13 | } 14 | 15 | print(studentId[101]) 16 | # print(studentId.get("101")) 17 | print(studentId.get(106, "Not a valid key")) 18 | print(studentId.get(103, "Not a valid key")) -------------------------------------------------------------------------------- /Program36.py: -------------------------------------------------------------------------------- 1 | # lambda function -> anonymous function (without name) , works with single line code 2 | 3 | # named function 4 | def calculate(a,b): 5 | result = (a*a) + 2*a*b + b*b 6 | return result 7 | 8 | 9 | def cube(x): 10 | return x * x * x 11 | 12 | 13 | # lambda parameter : expression 14 | a = (lambda a, b: (a*a) + 2 * a * b + b * b)(2, 3) 15 | 16 | 17 | cubeNumbers = (lambda x : x * x * x) (2) 18 | 19 | print(a) 20 | print(calculate(2,3)) 21 | print(cube(3)) 22 | print(cubeNumbers) -------------------------------------------------------------------------------- /Program17.py: -------------------------------------------------------------------------------- 1 | # Loop control statement -> while loop, for loop 2 | # while loop 3 | 4 | # print 1 to 100 5 | num = 1 6 | while num <= 100: 7 | print(num, end=" ") 8 | num = num + 1 9 | print("end") 10 | 11 | # print all the even numbers from 1 to 100 12 | num = 2 13 | while num <= 100: 14 | print(num, end=" ") 15 | num = num + 2 16 | print("end") 17 | 18 | # print all the odd numbers from 1 to 100 19 | num = 1 20 | while num <= 100: 21 | print(num, end=" ") 22 | num = num + 2 23 | print("end") -------------------------------------------------------------------------------- /Program41.py: -------------------------------------------------------------------------------- 1 | # How to read in a file python 2 | 3 | # step 1 : open a file 4 | # read mode -> r, write -> w, read and write -> r+ 5 | file = open("student.txt", "r") 6 | 7 | # checking a file is readable or not 8 | print(file.readable()) 9 | print(file.writable()) 10 | 11 | # reading the text from a a file 12 | text = file.read() 13 | print(text) 14 | 15 | size = len(text) 16 | print(size) 17 | 18 | lines = file.readlines() 19 | # lines = file.readlines() [0] 20 | print(lines) 21 | 22 | 23 | 24 | # always remember to close file at the end 25 | file.close() -------------------------------------------------------------------------------- /Program4.py: -------------------------------------------------------------------------------- 1 | # Basic Numerical operations -> +, -, *, /, % (modulus) , // (floor) , ** (exponential) 2 | num1 = 5 3 | num2 = 4 4 | 5 | result = num1 + num2 6 | print("Addition = ", result) 7 | 8 | result = num1 - num2 9 | print("Subtraction = ", result) 10 | 11 | result = num1 * num2 12 | print("Multiplication = ", result) 13 | 14 | result = num1 / num2 15 | print("Division = ", result) 16 | 17 | result = num1 % num2 18 | print("Remainder = ", result) 19 | 20 | result = num1 ** num2 21 | print("Exponential = ", result) 22 | 23 | result = num1 // num2 24 | print("Floor = ", result) -------------------------------------------------------------------------------- /Program25.py: -------------------------------------------------------------------------------- 1 | # A guessing game 2 | # import random 3 | from random import randint 4 | ''' 5 | start 6 | Input Guess Number 7 | Generate Random number 8 | If (guessNumber == randomNumber) 9 | i) yes, you have won 10 | ii) No, You have lost 11 | end 12 | ''' 13 | 14 | for x in range(1, 6): 15 | guessNumber = int(input("Enter your guess between 1 to 5 : ")) 16 | randomNumber = randint(1,5) 17 | # randomNumber = random.random() * 100 18 | if guessNumber == randomNumber: 19 | print("You have won") 20 | else: 21 | print("You have lost.Random number was ",randomNumber) -------------------------------------------------------------------------------- /Program15.py: -------------------------------------------------------------------------------- 1 | # Logical operator -> and, or, not 2 | # large number from 3 numbers using logical operator 3 | num1 = int(input("Enter first number : ")) 4 | num2 = int(input("Enter second number : ")) 5 | num3 = int(input("Enter third number : ")) 6 | 7 | if num1 > num2 and num1 > num3: 8 | print(num1) 9 | elif num2 > num1 and num2 > num3: 10 | print(num2) 11 | else: 12 | print(num3) 13 | 14 | # vowel / consonant program 15 | letter = input("Enter a letter : ") 16 | if letter == 'a' or letter == 'e' or letter == 'i' or letter == 'o' or letter == 'u': 17 | print("Vowel") 18 | else: 19 | print("Consonant") -------------------------------------------------------------------------------- /Program26.py: -------------------------------------------------------------------------------- 1 | # List as input from user 2 | 3 | # text = input("Enter a sentence : ") 4 | # words = text.split() 5 | # for word in words: 6 | # print(word) 7 | 8 | 9 | numOfLetters = 0 10 | numOfWords = 0 11 | numOfDigits = 0 12 | 13 | text = input("Enter a sentence : ") 14 | for x in text: 15 | x = x.lower() 16 | if 'a' <= x <= 'z': 17 | numOfLetters += 1 18 | elif '0' <= x <= '9': 19 | numOfDigits += 1 20 | elif x == ' ': 21 | numOfWords += 1 22 | 23 | print("Number of words = ", numOfWords + 1) 24 | print("Number of letters = ", numOfLetters) 25 | print("Number of digits = ", numOfDigits) -------------------------------------------------------------------------------- /Program31.py: -------------------------------------------------------------------------------- 1 | # stack -> append(), pop() LIFO and queue FIFO 2 | from collections import deque 3 | books = [] 4 | books.append("Learn c") 5 | books.append("Learn C++") 6 | books.append("Learn Java") 7 | print(books) 8 | 9 | books.pop() 10 | print("Now the last book is : ", books[-1]) 11 | 12 | books.pop() 13 | print("Now the last book is : ", books[-1]) 14 | 15 | books.pop() 16 | 17 | if not books: 18 | print("No books left") 19 | 20 | 21 | # queue example -> FIFO 22 | bank = deque(["x", "y", "z"]) 23 | print(bank) 24 | bank.popleft() 25 | print(bank) 26 | bank.popleft() 27 | bank.popleft() 28 | 29 | if not bank: 30 | print("No person left") -------------------------------------------------------------------------------- /Program29.py: -------------------------------------------------------------------------------- 1 | # tuples -> is a data structure like list but its value is not changeable (immutable) 2 | # tuples is faster than list 3 | students = ( 4 | "Anisul Islam", 5 | "Rabeya Begum", 6 | "Anwar Alam", 7 | ) 8 | 9 | print(students) 10 | print(students[0]) 11 | 12 | # value can not be changed 13 | # students[0] = "Misti" 14 | 15 | # nested touples 16 | studentsDetails = ( 17 | ("Name : Anisul Islam", "ID : 101", "Age : 30"), 18 | ("Name : Rabeya Begum", "ID : 102", "Age : 29"), 19 | ("Name : Rokibul Islam", "ID : 103", "Age : 30"), 20 | ) 21 | print(studentsDetails) 22 | print(studentsDetails[0]) 23 | print(studentsDetails[1:]) 24 | -------------------------------------------------------------------------------- /Program30.py: -------------------------------------------------------------------------------- 1 | # set -> an unordered collection of items. 2 | # duplicate value will be automatically removed 3 | # 2 ways to create set > set() , {} 4 | set1 = {1, 2, 3, 4, 5, 5 , 5 } 5 | print(type(set1)) 6 | print(set1) 7 | 8 | set2 = set([4,2,3,6]) 9 | print(set2) 10 | 11 | set2.add(7) 12 | print(set2) 13 | 14 | set2.remove(2) 15 | print(set2) 16 | 17 | # check an item is exist in a set 18 | print(7 in set2) 19 | print(7 not in set2) 20 | 21 | # set operations 22 | A = set([1,2,3,4]) 23 | B = set([4,5,6,7]) 24 | 25 | # UNION of 2 sets 26 | print(A | B) 27 | 28 | # Intersections of 2 sets 29 | print(A & B) 30 | 31 | # Differences of 2 sets 32 | print(A - B) -------------------------------------------------------------------------------- /Program3.py: -------------------------------------------------------------------------------- 1 | # Variables and data types 2 | 3 | # before using variables 4 | # print("Anisul Islam has a YouTube Channel") 5 | # print("He studies in Finland") 6 | # print ("Finland is the safest and happiest country in the world") 7 | # print("Anisul Islam is 30 years old now") 8 | # print("His Bachelor CGPA is 3.92 out of 4") 9 | 10 | # after using variables. variables helps us to reuse the data and change it whenever necessary 11 | name = "Anisul Islam" 12 | countryName = "Finland" 13 | age = 30 14 | cgpa = 3.92 15 | print(name + " has a YouTube Channel") 16 | print("He studies in "+ countryName) 17 | print (countryName + " is the safest and happiest country in the world") 18 | print(name + " is ", age , " years old now") 19 | print("His Bachelor CGPA is ", cgpa , " out of 4") -------------------------------------------------------------------------------- /Program43.py: -------------------------------------------------------------------------------- 1 | # Exceptions Handling -> try, except, finally (python) 2 | # Run time errors, compile time errors 3 | 4 | ''' 5 | # ZeroDivisionError -> 20 / 0 6 | # TypeError 7 | # ValueEroor -> 20 / a 8 | # IndexError -> x = [10,20], print(x[3]) 9 | 10 | num1 = int(input("Enter first number : ")) 11 | num2 = int(input("Enter second number : ")) 12 | result = num1 / num2 13 | print(result) 14 | print("Done") 15 | 16 | 17 | test = "Anis" 18 | print(test[2]) 19 | print(test[4]) 20 | print("Done") 21 | 22 | ''' 23 | try: 24 | list = [20,0,30] 25 | # result = list[0] / list[1] 26 | result = list[0] / list[3] 27 | print(result) 28 | 29 | except ZeroDivisionError: 30 | print("Dividing by 0 is not possible") 31 | 32 | except IndexError: 33 | print("Index is not found") 34 | 35 | finally: 36 | print("done") -------------------------------------------------------------------------------- /Program44.py: -------------------------------------------------------------------------------- 1 | # Exceptions Handling -> except, raise 2 | 3 | try: 4 | num1 = int(input("Enter 1st number : ")) 5 | num2 = int(input("Enter 2nd number : ")) 6 | result = num1 / num2 7 | print(result) 8 | 9 | except ValueError: 10 | print("Please enter only number") 11 | except ZeroDivisionError: 12 | print("You can not divide a number by 0") 13 | 14 | finally: 15 | print("Thank you!!!") 16 | 17 | ''' 18 | # multiple exception can be put together 19 | except (ValueError, ZeroDivisionError): 20 | print("Incorrect Input") 21 | ''' 22 | 23 | # raise exception 24 | def voter (age): 25 | if age < 18: 26 | raise ValueError("Invalid voter") 27 | return "You are allowed to vote" 28 | 29 | 30 | try: 31 | print(voter(19)) 32 | print(voter(16)) 33 | except ValueError as e: 34 | print(e) 35 | 36 | -------------------------------------------------------------------------------- /Program20.py: -------------------------------------------------------------------------------- 1 | # A program to demonstrate List 2 | subjects = ["C", "C++", "Java", "JavaScript", "Python"] 3 | print(subjects) 4 | 5 | # printing first element; index always start with 0 6 | print(subjects[0]) 7 | 8 | # printing all the elements starting from index 1 9 | print(subjects[1:]) 10 | 11 | # printing the last element 12 | print(subjects[-1]) 13 | 14 | # check an element exist or not 15 | print("Python" in subjects) 16 | print("python" in subjects) 17 | print("react" not in subjects) 18 | 19 | # can multiple elements by any number 20 | print(subjects*2) 21 | 22 | # list related functions 23 | # length of a list 24 | print("Length of student list : " , len(subjects)) 25 | 26 | # checking the position of an item 27 | pos = subjects.index("Java") 28 | print("Position of java in subjects : ", pos) 29 | 30 | # adding items at the end of a list 31 | subjects.append("php") 32 | print("After appending : ", subjects) 33 | 34 | # remove the last item of a list 35 | subjects.pop() 36 | print("Removing the last element : ", subjects) 37 | 38 | # inserting an item in list 39 | subjects.insert(3,"Database") 40 | print("After inserting : ", subjects) 41 | 42 | # removing an item 43 | subjects.remove("Java") 44 | print("After removing : ",subjects) 45 | 46 | # sorting a list 47 | subjects.sort() 48 | print("After sorting : ", subjects) 49 | 50 | numbers = [2,45,10,20,40,5,45] 51 | numbers.sort() 52 | print("Sorting numbers in ascending orders : ",numbers) 53 | 54 | numbers.reverse() 55 | print("Sorting numbers in descending orders : ",numbers) 56 | 57 | # clear the list 58 | subjects.clear() 59 | print("After clearing the list : ", subjects) 60 | 61 | # copy one list to another 62 | numbers2 = numbers.copy() 63 | print("numbers2 = ", numbers2) 64 | 65 | # count the appearance of an item 66 | x = numbers.count(45) 67 | print(x) 68 | 69 | --------------------------------------------------------------------------------