├── Chapter8 ├── report8797976.txt ├── report87979768.txt ├── certificate.txt ├── report.txt ├── fileBasics.py ├── mast.txt ├── bio.txt ├── practive3.py ├── newTextFile.txt ├── practice2.py ├── notes.txt ├── practice1.py ├── practice4.py └── fileReading.py ├── Chapter 0 ├── firstProgram.py └── Assignment1.py ├── Chapter 6 ├── passCode.py ├── range.py ├── practice8.py ├── practice3.py ├── forLoopBasic.py ├── practice7.py ├── practice5.py ├── practice4.py ├── loopsBasic.py ├── countDown.py └── practice1.py ├── Chapter 2 ├── keywords.py ├── dataTypes.py ├── implicit.py ├── practice1.py ├── printSum.py ├── smartTemperature.py ├── explicit.py └── operators.py ├── Chapter7 ├── practice2.py ├── returnBasic.py ├── functionbasic.py ├── FunctionParam.py ├── practice3.py └── practice1.py ├── Chapter 3 ├── indexing.py ├── stringBasic.py ├── practice2.py ├── slicing.py └── stringMethod.py ├── Chapter 1 ├── codeExecution.py ├── userInput.py └── Assignment2.py ├── Chapter 4 ├── listBasics.py ├── practice1.py ├── practice2.py ├── conditionalStatements.py ├── tupleBasics.py └── listMethods.py ├── Chapter 5 ├── practice1.py ├── setBasics.py ├── dictBasics.py └── practice2.py ├── Project2 └── main.py └── Project1 └── main.py /Chapter8/report8797976.txt: -------------------------------------------------------------------------------- 1 | Mai toh majak kar rahi thi -------------------------------------------------------------------------------- /Chapter8/report87979768.txt: -------------------------------------------------------------------------------- 1 | Mai toh majak kar rahi thi -------------------------------------------------------------------------------- /Chapter 0/firstProgram.py: -------------------------------------------------------------------------------- 1 | print("Hello World") 2 | 3 | -------------------------------------------------------------------------------- /Chapter 6/passCode.py: -------------------------------------------------------------------------------- 1 | for i in range(1,7): 2 | pass -------------------------------------------------------------------------------- /Chapter 2/keywords.py: -------------------------------------------------------------------------------- 1 | sweet= "Gulab Jamun" 2 | game = "Badminton" 3 | 4 | 5 | -------------------------------------------------------------------------------- /Chapter8/certificate.txt: -------------------------------------------------------------------------------- 1 | Score = 78 2 | Total Score = 100 3 | Score To Win = 90 -------------------------------------------------------------------------------- /Chapter8/report.txt: -------------------------------------------------------------------------------- 1 | ALL SETTTT ALL SETTTT ALL SETTTT My subscrbers are very intelligentMai toh majak kar rahi thi -------------------------------------------------------------------------------- /Chapter8/fileBasics.py: -------------------------------------------------------------------------------- 1 | file= open("mast.txt", "r") 2 | data= file.read() 3 | 4 | print("Data of the file is: ", data) -------------------------------------------------------------------------------- /Chapter 6/range.py: -------------------------------------------------------------------------------- 1 | # range(start, stop, step) 2 | 3 | for item in range(2, 21, 10): 4 | print(item) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Chapter8/mast.txt: -------------------------------------------------------------------------------- 1 | I am learning Python from Saumya. 2 | Enjoying in all classes. 3 | I feel sleepy sometimes but not always. -------------------------------------------------------------------------------- /Chapter8/bio.txt: -------------------------------------------------------------------------------- 1 | Bhuk lagi h 2 | L:ecture ke baad jakar momos kahungi 3 | Bhuk lagi h 4 | L:ecture ke baad jakar momos kahungi -------------------------------------------------------------------------------- /Chapter 6/practice8.py: -------------------------------------------------------------------------------- 1 | # Write a program using for and range() to print all even numbers between 1 2 | # and 20. 3 | 4 | for i in range(2, 21, 2): 5 | print(i) -------------------------------------------------------------------------------- /Chapter 2/dataTypes.py: -------------------------------------------------------------------------------- 1 | food= "Samosa" 2 | age= 25 3 | area= 670.98 4 | name= "Khushi" 5 | 6 | print("Data type of variable name is", type(name)) 7 | print(type(area)) -------------------------------------------------------------------------------- /Chapter7/practice2.py: -------------------------------------------------------------------------------- 1 | # Write a function square(num) that returns the square of a number. 2 | 3 | def square(num=10): 4 | return num**2 5 | 6 | print(square(3)) -------------------------------------------------------------------------------- /Chapter8/practive3.py: -------------------------------------------------------------------------------- 1 | # Read only the first line of bio.txt 2 | 3 | with open("bio.txt", "r") as f: 4 | line1= f.readline() 5 | print("Line 1", line1) 6 | 7 | -------------------------------------------------------------------------------- /Chapter8/newTextFile.txt: -------------------------------------------------------------------------------- 1 | I am Saumya 2 | I am a soft engg with 5+ years of experience 3 | I love travelling 4 | I love teaching 5 | I love dancing but I cant dance 6 | -------------------------------------------------------------------------------- /Chapter8/practice2.py: -------------------------------------------------------------------------------- 1 | # Open a file called report.txt in write mode. 2 | 3 | file= open("report87979768.txt", "x") 4 | file.write("Mai toh majak kar rahi thi") 5 | 6 | -------------------------------------------------------------------------------- /Chapter 3/indexing.py: -------------------------------------------------------------------------------- 1 | str1= "Divya's name is very nice" 2 | length= len(str1) 3 | print(length) #5 4 | print(str1[0]) #D 5 | print(str1[4]) #a 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Chapter 0/Assignment1.py: -------------------------------------------------------------------------------- 1 | # Assignement Question : Print your name 10 times using * symbol and each time it should be on next line 2 | 3 | print(("Saumya Singh" + "\n") * 10) 4 | -------------------------------------------------------------------------------- /Chapter8/notes.txt: -------------------------------------------------------------------------------- 1 | Mai bht achi bachi huin 2 | Iske baad office ka kaam karungi 3 | Kuch lectures aur bache hai 4 | Certificate app ke andar mil jayega 5 | Job Ready kit bhi h -------------------------------------------------------------------------------- /Chapter7/returnBasic.py: -------------------------------------------------------------------------------- 1 | # Return Statement 2 | 3 | def multiply(a=10, b=10): 4 | return a*b 5 | 6 | print(multiply(10, 10)) 7 | result= multiply(5, 10) 8 | print(result) 9 | 10 | -------------------------------------------------------------------------------- /Chapter 2/implicit.py: -------------------------------------------------------------------------------- 1 | #implicit conversion (automatically) 2 | x= 5 #int 3 | y= 10.5 #float 4 | z= x+y #float 5 | 6 | print("answer is ", z) 7 | print("data type of answer is ", type(z)) 8 | 9 | 10 | -------------------------------------------------------------------------------- /Chapter 1 /codeExecution.py: -------------------------------------------------------------------------------- 1 | name = "Saumya Singh" 2 | age1 = 25 3 | age2 = 40 4 | print("Actual Value:" , age2) 5 | favSubject = "Maths" 6 | age2 = age1 7 | print("Changed Value:" , age2) 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter 2/practice1.py: -------------------------------------------------------------------------------- 1 | # program to take age as input and print value entered and its data type 2 | 3 | age = input("Enter your age : ") 4 | print("Value entered is :", age) 5 | print("Data type is : ", type(age)) -------------------------------------------------------------------------------- /Chapter 2/printSum.py: -------------------------------------------------------------------------------- 1 | # input 2 numbers and print sum 2 | 3 | input1= int(input("Enter first number")) 4 | input2= int(input("Enter second number")) 5 | sum= input1 + input2 6 | 7 | print("Sum of the 2 values is", sum) -------------------------------------------------------------------------------- /Chapter 1 /userInput.py: -------------------------------------------------------------------------------- 1 | # Program to take input from the user 2 | 3 | print("A sample program to understand input method in python") 4 | 5 | name= input("Enter your good name :") 6 | 7 | print("Your good name is :", name) 8 | 9 | -------------------------------------------------------------------------------- /Chapter 4/listBasics.py: -------------------------------------------------------------------------------- 1 | # Lists in Python 2 | 3 | food= ["chole bathure", "choco waffle", "gulab jamun", "apple", "mango", 7] 4 | print(len(food)) 5 | 6 | print("First Value of the list:", food[0]) 7 | print("First Value of the list:", food[3]) 8 | -------------------------------------------------------------------------------- /Chapter 2/smartTemperature.py: -------------------------------------------------------------------------------- 1 | # take input celsius 2 | 3 | celsius= float(input("Enter The Value: ")) 4 | 5 | # print fahrenheit equivalent of celsius 6 | fahren= (celsius*(9/5)) + 32 7 | 8 | print("Fahrenheit value is: ", fahren) 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Chapter 6/practice3.py: -------------------------------------------------------------------------------- 1 | # Write a program to print all even numbers between 1 and 50 using a while 2 | # loop. 3 | 4 | # even num = 2, 4, 6, 8 5 | 6 | num= 1 7 | 8 | while (num<=50): 9 | if(num%2 == 0): 10 | print(num) 11 | num= num+1 12 | 13 | -------------------------------------------------------------------------------- /Chapter 4/practice1.py: -------------------------------------------------------------------------------- 1 | # take input and print posotive if num is greater than zero and so on 2 | 3 | num= int(input("Enter a number :")) 4 | 5 | if(num>0): 6 | print("Positive") 7 | elif(num==0): 8 | print("Zero") 9 | else: 10 | print("Negative") 11 | 12 | -------------------------------------------------------------------------------- /Chapter 6/forLoopBasic.py: -------------------------------------------------------------------------------- 1 | foodList= ["cake", "mango", "pizza"] 2 | 3 | for item in foodList: 4 | print(item) 5 | 6 | collegesTuple = ("NIT-Delhi", "ABES", "BBAU", "IIT-D", "IIT-H") 7 | 8 | for eachItem in collegesTuple: 9 | print("Colleges Visited by Saumya" , eachItem) -------------------------------------------------------------------------------- /Chapter 3/stringBasic.py: -------------------------------------------------------------------------------- 1 | str1= 'Hello' 2 | str2= "Saumya" 3 | str3= '''Python Course by Saumya Di''' 4 | 5 | print(str1) 6 | print(str2) 7 | print(str3) 8 | 9 | # string concatenation 10 | print(str1 + " " + str2) 11 | 12 | #length of string 13 | print( len(str1)) 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter 1 /Assignment2.py: -------------------------------------------------------------------------------- 1 | # Question - Take diameter as input and calculate the area of a circle. 2 | 3 | 4 | diameter = int(input("Inter the value of diameter: ")) 5 | radius = diameter/2 6 | area = 3.14 * (radius ** 2) 7 | print("Radius of the circle is", radius) 8 | print("Area of circle is", area) 9 | -------------------------------------------------------------------------------- /Chapter 6/practice7.py: -------------------------------------------------------------------------------- 1 | # Write a program to print the multiplication table of any number using a while 2 | # loop. 3 | # (Hint: Start i = 1 and run the loop until i <= 10.) 4 | 5 | n= int(input("Enter a number : ")) 6 | i= 1 7 | 8 | while i<=10: 9 | print(f"{n} x {i} = {n*i} ") 10 | i= i+1 -------------------------------------------------------------------------------- /Chapter 3/practice2.py: -------------------------------------------------------------------------------- 1 | # question on slicing 2 | #take input and print middle 3 charaters , last 2 character 3 | 4 | #green 5/2 5 | 6 | str= input("Enter the value: ") 7 | mid= len(str)//2 8 | output1= str[mid-1:mid+2] 9 | print(output1) 10 | 11 | output2= str[-2:] 12 | print(output2) 13 | 14 | 15 | -------------------------------------------------------------------------------- /Chapter 6/practice5.py: -------------------------------------------------------------------------------- 1 | # Write a program to print this pattern using a while loop: 2 | # * 3 | # * * 4 | # * * * 5 | # * * * * 6 | 7 | n= 1 8 | 9 | while n<=4: 10 | print("*" * n) 11 | n= n+1 12 | 13 | print("We are out of the while loop, and value of n should be 5. Is it 5? check : ", n) 14 | -------------------------------------------------------------------------------- /Chapter 5/practice1.py: -------------------------------------------------------------------------------- 1 | # Create a dictionary named marks to store marks of 3 subjects. 2 | # Add the subjects one by one and print the final dictionary 3 | 4 | marks= {} 5 | # print(type(marks)) 6 | 7 | marks["Maths"]= 99 8 | marks["Chemistry"]= 99 9 | marks["Computer Science"]= 91 10 | 11 | print(marks) 12 | -------------------------------------------------------------------------------- /Chapter 5/setBasics.py: -------------------------------------------------------------------------------- 1 | food= {"paneer", "chole bathure", "sandwitch", "golgappe", "paneer"} 2 | print(type(food)) 3 | print(food) 4 | food.add("Kunafa") 5 | print(food) 6 | food.remove("chole bathure") 7 | print(food) 8 | 9 | # sets do not entertain duplicacy 10 | 11 | emptySet= set() 12 | print(type(emptySet)) 13 | -------------------------------------------------------------------------------- /Chapter7/functionbasic.py: -------------------------------------------------------------------------------- 1 | # Functions Basic 2 | 3 | def sumFunc() : 4 | a=4 5 | b=8 6 | sum=a+b 7 | print(sum) 8 | 9 | 10 | sumFunc() # print 12 11 | # Function Calling 12 | 13 | # # .... 100 line of code 14 | 15 | sumFunc() # print 12 16 | 17 | # # .... 100 line of code 18 | 19 | sumFunc() # print 12 -------------------------------------------------------------------------------- /Chapter 3/slicing.py: -------------------------------------------------------------------------------- 1 | #understanding slicing concept 2 | 3 | str= "GulabJamun" 4 | 5 | firstHalf= str[0:5] #Gulab 6 | trialFirstHalf= str[ :5] #Gulab 7 | 8 | print(firstHalf) 9 | print(trialFirstHalf) 10 | 11 | secondHalf= str[5:10] #Jamun 12 | trialSecondHalf= str[5: ] #Jamun 13 | 14 | print(secondHalf) 15 | print(trialSecondHalf) -------------------------------------------------------------------------------- /Chapter 3/stringMethod.py: -------------------------------------------------------------------------------- 1 | str= "Saumya singh" 2 | print(str.upper()) 3 | print(str.lower()) 4 | print(str.title()) 5 | print(str.find("ng")) 6 | print(str.replace("singh", "Best")) 7 | print(str.count("a")) #count the occurence 8 | 9 | #escape sequence 10 | 11 | print("Hello World") 12 | print("Hello\nWorld") 13 | print("Hello \t World") 14 | -------------------------------------------------------------------------------- /Chapter 6/practice4.py: -------------------------------------------------------------------------------- 1 | # Write a program that prints the sum of first n natural numbers. 2 | # For example, if n = 5, then output should be 1 + 2 + 3 + 4 + 5 = 15. 3 | 4 | n= int(input("Enter a number: ")) 5 | sum= 0 6 | 7 | while n>=1: 8 | sum= sum+n 9 | n= n-1 10 | 11 | print("Sum= ", sum) 12 | print("n= ", n) 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter 4/practice2.py: -------------------------------------------------------------------------------- 1 | # take 3 food and store in list, print list and length 2 | 3 | food1= input("Enter food 1:") 4 | food2= input("Enter food 2:") 5 | food3= input("Enter food 3:") 6 | 7 | foodList= [] 8 | foodList.append(food1) 9 | foodList.append(food2) 10 | foodList.append(food3) 11 | 12 | 13 | print(foodList) 14 | print(len(foodList)) 15 | -------------------------------------------------------------------------------- /Chapter 2/explicit.py: -------------------------------------------------------------------------------- 1 | # take num as input 2 | # convert to float and print both orginal & converted 3 | # value with their data types 4 | 5 | num= input( "Enter a value : ") 6 | convertedValue = float(num) 7 | 8 | print("Orginal Value is ", num, "Data Type :", type(num)) 9 | 10 | print("Converted Value is ", convertedValue, "Data Type :", type(convertedValue)) 11 | -------------------------------------------------------------------------------- /Chapter8/practice1.py: -------------------------------------------------------------------------------- 1 | # Write a program to read a text from a given file certificate.txt 2 | # and find whether it contains the word live. 3 | 4 | file= open("certificate.txt", "r") 5 | dataOfFile= file.read() 6 | 7 | dataOfFile= dataOfFile.lower() 8 | 9 | if "live" in dataOfFile: 10 | print("Yes Live word is present in the file") 11 | else: 12 | print("No") 13 | -------------------------------------------------------------------------------- /Chapter 4/conditionalStatements.py: -------------------------------------------------------------------------------- 1 | #conditional statements 2 | 3 | # marks= 95 4 | 5 | # if(marks >= 90): 6 | # print("Your grade is A") 7 | # elif(marks >= 80): 8 | # print("Your grade is B") 9 | 10 | age= 16 11 | 12 | if(age>=18): 13 | print("You are eligible to vote") 14 | else: 15 | print("You are not eligible to vote") 16 | 17 | print("My code ends here") -------------------------------------------------------------------------------- /Chapter 6/loopsBasic.py: -------------------------------------------------------------------------------- 1 | # while loop and for loop 2 | # print the name 100 times 3 | 4 | num = 1 5 | 6 | while num<=5: 7 | print("Saumya Singh") 8 | num= num+1 9 | 10 | print("Now we are out of the while loop") 11 | 12 | ''' 13 | num= 1 Saumya Singh 14 | 2 Saumya Singh 15 | 3 Saumya Singh 16 | 4 Saumya Singh 17 | num= 5 Saumya Singh 18 | "Now we are out of the while loop 19 | ''' 20 | -------------------------------------------------------------------------------- /Chapter 6/countDown.py: -------------------------------------------------------------------------------- 1 | # Goal: 2 | # Print a countdown before something “exciting” happens (like “Launching…” or 3 | # “Happy New Year!”). 4 | 5 | import time 6 | 7 | count= int(input("Enter the counter num: ")) 8 | 9 | print("\n Countdown Starts Now: ") 10 | 11 | for i in range(count,0,-1): 12 | print(i) 13 | time.sleep(1) 14 | 15 | print("\n WOHOOO! Happy New Year") 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Chapter 6/practice1.py: -------------------------------------------------------------------------------- 1 | # Write a Python program to print numbers from 1 to 10 using a while loop. 2 | 3 | i= 1 4 | 5 | while (i<=10): 6 | print(i) 7 | i+=1 8 | 9 | print("Quest 1 complete") 10 | 11 | 12 | # Write a program to print numbers from 10 down to 1 using a while loop. 13 | 14 | j=10 15 | while (j>=1): 16 | print(j) 17 | j=j-1 18 | print("j =", j) 19 | 20 | print("Quest 2 complete") 21 | 22 | 23 | -------------------------------------------------------------------------------- /Chapter 4/tupleBasics.py: -------------------------------------------------------------------------------- 1 | #tuples Basics 2 | 3 | myTuple= (78, 90, 75) 4 | studentTuple= ("Khushi", "Divya", "Ishaan", "Divya") 5 | print(len(myTuple)) 6 | # studentTuple[1]= "Aanchal" Tuples are IMMUTABLE/NOT Changeable 7 | 8 | print(studentTuple[2]) 9 | 10 | #empty Tuples 11 | emptyTuple= () 12 | singleTuple= (1,) 13 | print(type(emptyTuple)) 14 | print(type(singleTuple)) 15 | print(studentTuple.index("Divya")) 16 | print(studentTuple.count("Aditya")) 17 | 18 | -------------------------------------------------------------------------------- /Chapter8/practice4.py: -------------------------------------------------------------------------------- 1 | # Print how many lines are present in notes.txt 2 | import os 3 | 4 | try: 5 | with open("notes.txt", "r") as f: 6 | listOfLines= f.readlines() 7 | print("Output of readLines Function", listOfLines) 8 | print("Number of Lines in File", len(listOfLines)) 9 | except: 10 | print("That files does not exist") 11 | 12 | # RENAMING THE FILE 13 | 14 | # os.rename("report2.txt", "khushi.txt") 15 | # os.remove("khushi.txt") -------------------------------------------------------------------------------- /Chapter 5/dictBasics.py: -------------------------------------------------------------------------------- 1 | # Dictionary Basics 2 | 3 | student= { 4 | "name": "Saumya Singh", 5 | "city": "Sultanpur", 6 | "age": 25, 7 | "rollNumber": 23, 8 | } 9 | 10 | print(type(student)) 11 | print(student["name"]) 12 | print(student) 13 | print(student["city"]) 14 | # student["city"]= "Hyderabad" 15 | # print(student) 16 | student["favSubject"]= "Maths" 17 | print(student) 18 | student.pop("favSubject") 19 | print(student) 20 | print(student.items()) 21 | -------------------------------------------------------------------------------- /Chapter 4/listMethods.py: -------------------------------------------------------------------------------- 1 | # Methods in List 2 | 3 | #LIsts are mutable 4 | marks= [99, 100, 90, 95] 5 | print(marks) 6 | 7 | # marks[1]= 98 8 | # print(marks) 9 | 10 | #Slicing 11 | print(marks[1:3]) 12 | print(max(marks)) 13 | print(min(marks)) 14 | marks.append(92) 15 | print(marks) 16 | marks.sort() 17 | print(marks) 18 | marks.pop(1) 19 | print(marks) 20 | marks.remove(100) 21 | print(marks) 22 | marks.insert(1,100) 23 | print(marks) 24 | 25 | 26 | # # STRINGS ARE IMMUTABLE 27 | # name= "Saumya" 28 | # name[1]= "o" 29 | # print(name) 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Chapter7/FunctionParam.py: -------------------------------------------------------------------------------- 1 | 2 | # Function Definition with Parameters 3 | def average(a=10,b=20): 4 | averageValue= (a+b)/2 5 | print(averageValue) 6 | 7 | 8 | # Function Calling with Arguments 9 | average(5, 10) 10 | average(7, 10) 11 | average(80, 98) 12 | average() 13 | 14 | # Write a function show_age(name, age) that prints: "Saumya Singh is 21 15 | # years old." 16 | 17 | def show_age(name="Saumya Singh", age= 25): 18 | print(f"{name} is {age} years old") 19 | 20 | show_age("Saumya Singh", 25) 21 | show_age() 22 | show_age("Divya", 19) 23 | 24 | -------------------------------------------------------------------------------- /Chapter 5/practice2.py: -------------------------------------------------------------------------------- 1 | # You are given a list of programming languages: 2 | # ["Python", "Java", "C++", "Python", "Java", "C"] 3 | # Convert it into a set and print how many unique languages Divya knows. 4 | 5 | programmingList= ["Python", "Java", "C++", "Python", "Java", "C"] 6 | print(type(programmingList)) 7 | # how to convert a list into set 8 | 9 | programmingSet= set(programmingList) 10 | print(type(programmingSet)) 11 | print(programmingSet) 12 | print("Divya knows these many langauges", len(programmingSet)) 13 | 14 | # Mini Project 4 – Countdown Timer 15 | # Created by: Saumya Singh 16 | 17 | -------------------------------------------------------------------------------- /Chapter 2/operators.py: -------------------------------------------------------------------------------- 1 | # arithmetic operators 2 | 3 | x= 10 4 | y= 5 5 | 6 | print(x+y) 7 | print(x-y) 8 | print(x*y) 9 | print(x/y) 10 | print(x%y) 11 | print(x**y) 12 | 13 | #comparison operators 14 | 15 | print(x==y) #false 16 | print(xy) #true 18 | 19 | # logical operators 20 | 21 | print("AND Operator Result ", x>y and xy or xy)) #false 24 | 25 | # Assignment operator 26 | 27 | a= 2 28 | b= 3 29 | 30 | a= a+6 31 | a+=6 32 | 33 | 34 | a= a-1 35 | a-=1 36 | 37 | a=a/10 38 | a/=10 39 | 40 | a=a*10 41 | a*=10 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Chapter7/practice3.py: -------------------------------------------------------------------------------- 1 | # Write a function that takes a string and returns the count of vowels and 2 | # consonants separately. 3 | 4 | def countVowConso(userInput): 5 | 6 | #define vowels 7 | vowels= "aeiouAEIOU" 8 | 9 | countVowel= 0 10 | countConsonants= 0 11 | 12 | #SAUMYA123 13 | for eachChar in userInput: 14 | if(eachChar.isalpha()): 15 | if(eachChar in vowels): 16 | countVowel= countVowel+1 17 | else: 18 | countConsonants+=1 19 | 20 | return countVowel, countConsonants 21 | 22 | 23 | # Function Call 24 | 25 | vowels, consonants= countVowConso("Saumya Singh") 26 | 27 | print(vowels, consonants) 28 | print(vowel) -------------------------------------------------------------------------------- /Chapter8/fileReading.py: -------------------------------------------------------------------------------- 1 | # with keyword 2 | 3 | # file = open("report.txt", "r") 4 | # data= file.read() 5 | # print("File Data", data) 6 | # file.close() 7 | 8 | # with open("report.txt", "r") as f: 9 | # data= f.read() 10 | 11 | with open("newTextFile.txt", "r") as f: 12 | # line1= f.readline() 13 | # line2= f.readline() 14 | # line3= f.readline() 15 | # line4= f.readline() 16 | # line5= f.readline() 17 | # line6= f.readline() 18 | # data= f.read() 19 | # print("Line 1 ", line1) 20 | # print("Line 2", line2) 21 | # print("Line 3", line3) 22 | # print("Line 4", line4) 23 | # print("Line 5", line5) 24 | # print("Line 6", line6) 25 | # print("File Data", data) 26 | readLinesMethod= f.readlines() 27 | print(readLinesMethod) -------------------------------------------------------------------------------- /Chapter7/practice1.py: -------------------------------------------------------------------------------- 1 | # Write a function named welcome_message() that prints “Welcome to 2 | # Python Programming!” three times. 3 | 4 | 5 | # Simple Func Definituon without any Param 6 | def welcome_message(): 7 | print("Welcome to Python Course by Saumya") 8 | print("Line 2") 9 | 10 | 11 | welcome_message() #function is being called 12 | welcome_message() #function is being called 13 | welcome_message() #function is being called 14 | 15 | # Define a function inspire() that prints a motivational quote with your 16 | # name. 17 | 18 | # FUNCTION DEFINITION , we have only defined the function here 19 | def inspire(): 20 | print("You are the master of your destiny: Saumya Singh") 21 | 22 | inspire() 23 | 24 | # Simple Function Call with No Argument 25 | def IamBest(): 26 | print("Just a Trial Function") 27 | 28 | IamBest() -------------------------------------------------------------------------------- /Project2/main.py: -------------------------------------------------------------------------------- 1 | #Rule Based AI Python ChatBot 2 | 3 | import datetime 4 | import time 5 | 6 | name= input("Swagat h, enter your name : ") 7 | presentHour= datetime.datetime.now().hour 8 | 9 | if 5 <= presentHour <= 11: 10 | print("Good morning, ", name) 11 | elif 11 <= presentHour <= 17: 12 | print("Good afternoon, ", name) 13 | elif 17 <= presentHour <= 20: 14 | print("Good evening, ", name) 15 | else: 16 | print("Good night, ", name) 17 | 18 | 19 | 20 | print("Namaste! Welcome to Your ChatBot") 21 | print("You can ask me basic question, Type 'bye' to exit from the bot") 22 | 23 | # Chatbot Memory Creation [ dictionary of responses ] 24 | 25 | responses = { 26 | "hello": "Hi, welcome. How can I help you?", 27 | "how are you": "I am very fine. Thank you", 28 | "who are you": "I am smart AI chatbot", 29 | "motivate me": "Keep going. Every bug of your project makes you a better developer", 30 | "happy": "Great to hear that", 31 | "functions kya hote hai": "jakar chapter 7 padho" 32 | } 33 | 34 | # Method/Function to get response of ChatBot 35 | 36 | def getResponseOfBot(userQuestion): 37 | userQuestion= userQuestion.lower() 38 | for eachKey in responses: 39 | if eachKey in userQuestion: 40 | return responses[eachKey] 41 | 42 | return "I am not able to tell that yet. Mai jald hi ye sikh lunga" 43 | 44 | 45 | # Take user input 46 | 47 | 48 | while True: 49 | userInput= input("Please ask your question:") 50 | reply= getResponseOfBot(userInput) 51 | print("Bot Response:", reply) 52 | 53 | if "bye" in userInput.lower(): 54 | break 55 | -------------------------------------------------------------------------------- /Project1/main.py: -------------------------------------------------------------------------------- 1 | # Expense Tracker Project 2 | 3 | expensesList = [] #list of expenses in form of dictionary 4 | print(" Welcome to Expense Tracker : ") 5 | 6 | while True: 7 | print("====MENU====") 8 | print("1. Add Expense") 9 | print("2. View All Expenses") 10 | print("3. View Total Khrcha") 11 | print("4. Exit") 12 | 13 | choice= int(input("Please Enter Your Choice : ")) 14 | 15 | #ADD Expense 16 | if(choice == 1): 17 | date= input("Kis date par khrcha kiya tha?: ") 18 | category= input("Kis type ka khrcha kiya? (Food, Travel, Makeup, Books): ") 19 | description= input("Aur detail dedo: ") 20 | amount= float(input("Enter the amount: ")) 21 | 22 | expense= { 23 | "date": date, 24 | "category": category, 25 | "description": description, 26 | "amount": amount 27 | } 28 | 29 | expensesList.append(expense) 30 | print(" \n DONE bro. Expense is added succesfully") 31 | 32 | # 2. VIEW ALL EXPENSES 33 | elif(choice == 2): 34 | if( len(expensesList)==0 ): 35 | print("No Expenses Added. Jao pehle khrcha karo. ") 36 | else: 37 | print("===== Ye y apka sara expense ======") 38 | count= 1 39 | for eachKharcha in expensesList: 40 | print(f"Kharcha Number {count} -> {eachKharcha["date"]}, {eachKharcha["category"]}, {eachKharcha["description"]}, {eachKharcha["amount"]} ") 41 | count= count+1 42 | 43 | # 3. View TOtal Spending 44 | elif(choice == 3): 45 | total= 0 46 | for eachKrcha in expensesList: 47 | total = total + eachKrcha["amount"] 48 | 49 | print("\n TOTAL KHRCHA = ", total) 50 | 51 | #4. EXIT 52 | elif(choice == 4): 53 | print("Dhanyawad aaapne humara system use kiya") 54 | break 55 | 56 | else: 57 | print("INVALID CHOICE. TRY AGAIN") 58 | --------------------------------------------------------------------------------