├── Dictionaries.py
├── Exp1.py
├── FileHandling.py
├── List.py
├── Questions
├── Q1.py
├── Q2.py
├── Q3.py
├── Q4.py
└── Q5.py
├── SEE.py
├── Sets.py
├── Tuple.py
├── UrlOpen.txt
├── __pycache__
└── mod.cpython-312.pyc
├── bin.txt
├── copy.txt
├── mod.py
├── revision 2.py
├── revision 3.py
├── revision.py
└── text.txt
/Dictionaries.py:
--------------------------------------------------------------------------------
1 | d = {'User': "Mark", 'Pass': "Phoenix"}
2 | d.update({'id': 2398498})
3 | # d.pop("id")
4 | rem = d.popitem()
5 | print(d)
6 | print(type(d))
7 | print(rem)
8 |
--------------------------------------------------------------------------------
/Exp1.py:
--------------------------------------------------------------------------------
1 | class Car:
2 | __auth_key = 345678663
3 |
4 | def __init__(self, name, model, key):
5 | self.name = name
6 | self.model = model
7 | self.key = key
8 | if self.key == Car.__auth_key:
9 | self.validity = "Valid :)"
10 | else:
11 | self.validity = "Invalid :("
12 |
13 |
14 | # Ask the user for car details
15 | Name = input("Enter the Car Name: ")
16 | Model = input("Enter the Car Model: ")
17 | Key = int(input("Enter the key: "))
18 |
19 | # Create an instance of the Car class
20 | car = Car(Name, Model, Key)
21 |
22 | # Print car details
23 | print(f"Name: {car.name}\nModel: {car.model}\nKey: {car.key}\nValidity: {car.validity}")
24 |
--------------------------------------------------------------------------------
/FileHandling.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | f = open("Text.txt", 'r+')
4 |
5 | """f.write('Hello World\n')
6 | f.write('This is my programme\n')
7 | f.write('Hehe\n')
8 | f.write(':)\n')"""
9 | # print(f.read())
10 | for line in f:
11 | print(line, end='')
12 | # os.rename("Text.txt", "text.txt")
13 |
14 | f.close()
--------------------------------------------------------------------------------
/List.py:
--------------------------------------------------------------------------------
1 | import functools
2 |
3 | def add_2(x):
4 | x += 2
5 | return x
6 |
7 | def add(x, y):
8 | return x+y
9 |
10 |
11 | my_list = ["Apple", "Berry", "Cherries", "DragonFruit", "Berry", "Cherries"]
12 | conv_list = list(('A', 'B', 'C', 'D'))
13 | diff_list = ["Apple", 12, True, 13.5, 'C']
14 | conv_list.insert(4, 'E')
15 | pop = conv_list.pop(4)
16 | my_tuple = ('A', 'B', 'C')
17 | sort_list = [1, 6, 3, 33, 45, 23, 12, 4]
18 | sort_list.sort()
19 | conv_list.insert(5, my_tuple)
20 | new_list = my_list.copy()
21 | # diff_list.reverse()
22 | map_list = list(map(add_2, sort_list))
23 |
24 |
25 | # print(my_list)
26 | # print(conv_list)
27 | # print(diff_list)
28 | # print(type(diff_list))
29 | # print(my_list[0])
30 | # print(my_list[0::2])
31 | # print(my_list[5:0:-1])
32 | # print(pop)
33 | # print("Return value: ", conv_list.pop())
34 | # print(new_list)
35 | # print(diff_list)
36 | # print(sort_list)
37 | """for my_list in my_list:
38 | print(my_list)"""
39 | """for i in range(len(my_list)):
40 | print(my_list[i])"""
41 | # print(map_list)
42 | # print(functools.reduce(add, sort_list))
43 |
44 |
--------------------------------------------------------------------------------
/Questions/Q1.py:
--------------------------------------------------------------------------------
1 | f = open("../Text.txt", "r")
2 | lines = f.readlines()
3 | count = 0
4 | for line in lines:
5 | if line[0] == 'M' or line[0] == 'm':
6 | continue
7 | else:
8 | count += 1
9 | print("No of Lines",count)
10 | f.close()
11 |
--------------------------------------------------------------------------------
/Questions/Q2.py:
--------------------------------------------------------------------------------
1 | def frequency(file_name, word):
2 | try:
3 | with open(file_name, "r") as f:
4 | occurrence = 0
5 | for line in f:
6 | occurrence += line.lower().count(word.lower())
7 | print("Occurrences =", occurrence)
8 | except FileNotFoundError:
9 | print("File not found :(")
10 |
11 |
12 | filename = "../Text.txt"
13 | word_to_find = "Malevolent"
14 | frequency(filename, word_to_find)
--------------------------------------------------------------------------------
/Questions/Q3.py:
--------------------------------------------------------------------------------
1 | def seperator(file_name,sep_agent):
2 | try:
3 | with open(file_name, "r") as f:
4 | content = f.read()
5 | formatted_content = sep_agent.join(content)
6 | print(formatted_content)
7 |
8 | except FileNotFoundError:
9 | print("File not found :(")
10 |
11 |
12 | file = "../Text.txt"
13 | symbol = '*'
14 | seperator(file, symbol)
15 |
--------------------------------------------------------------------------------
/Questions/Q4.py:
--------------------------------------------------------------------------------
1 | class Dog:
2 | species = "Canine"
3 |
4 | def __init__(self, name, breed):
5 | self.name = name
6 | self.breed = breed
7 |
8 |
9 | sammi = Dog("Sammi", "Husky")
10 | casey = Dog("Casey", "Chocolate Lab")
11 |
12 | print(f"{sammi.name} is a {sammi.breed} - {Dog.species}")
13 | print(f"{casey.name} is a {casey.breed} - {Dog.species}")
14 |
--------------------------------------------------------------------------------
/Questions/Q5.py:
--------------------------------------------------------------------------------
1 | class Person:
2 | def __init__(self, name):
3 | self.name = name
4 |
5 |
6 | user_input = input("Enter your name: ")
7 |
8 | person = Person(user_input)
9 | print("Name: ", person.name)
--------------------------------------------------------------------------------
/SEE.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | """str = "Hello World"
4 | print(str[0:12:2])"""
5 |
6 | """
7 | for i in range(0,20):
8 | if i == 12:
9 | print("Umm")
10 | continue
11 | elif i == 13:
12 | continue
13 | elif i == 14:
14 | print("hehe :)")
15 | continue
16 | print(i)
17 | """
18 |
19 | """
20 | def add(x,y):
21 | return x+y
22 | result = add(2,3)
23 | print(f"Result: {result}")"""
24 |
25 | """
26 | def adder(*var):
27 | result = 0
28 | for i in range(len(var)):
29 | if var[i] == 0 and (i+1 < len(var) and var[i+1] == 0):
30 | break
31 | result += var[i]
32 | return result
33 |
34 | output = adder(1, 2, 3, 0, 5, 56, 6, 7, 7)
35 | print(f"Value: {output}")
36 |
37 | """
38 |
39 | """
40 | def fact(n):
41 | if n == 0 or n == 1:
42 | return 1
43 | else:
44 | return n * fact(n - 1)
45 |
46 | result = fact(5)
47 | print(f"Factorial: {result}")
48 | """
49 |
50 | """
51 | add = lambda x, y: x + y
52 | value = add(2, 3)
53 | print(f"Value: {value}")
54 | """
55 |
56 | """
57 | file = "Text.txt"
58 | with open(file,'r') as f:
59 | str = f.read()
60 | print(str)
61 | """
62 |
63 | """
64 | try:
65 | os.rename("ttext.txt", "text.txt")
66 | except FileNotFoundError:
67 | print("File Not Found")
68 | """
69 |
70 | """
71 | with open("text.txt", 'r') as f1:
72 | with open("bin.txt", 'w') as f2:
73 | data = f1.read()
74 | f2.writelines(data)
75 | #os.remove("bin.txt")
76 | """
77 |
78 | """
79 | def count_words(filename):
80 | count = 0
81 | with open(filename) as f:
82 | for line in f:
83 | if line and not line.lstrip().startswith('M'):
84 | count += 1
85 | return count
86 |
87 | result = count_words("text.txt")
88 | print(f"Number of lines that starts without M: {result}")
89 | """
90 |
91 | """
92 | class Dog:
93 | species = "canine"
94 |
95 | def __init__(self, name, breed):
96 | self.name = name
97 | self.breed = breed
98 |
99 | dog1 = Dog("Sammi", "Husky")
100 | dog2 = Dog("Casey", "Chocolate Lab")
101 |
102 | print(f"Dog: Name: {dog1.name}, Breed: {dog1.breed}, species = {Dog.species}")
103 | print(f"Dog: Name: {dog2.name}, Breed: {dog2.breed}, species = {Dog.species}")
104 | """
105 |
106 | """
107 | class Student:
108 | def __init__(self, name, marks):
109 | self.name = name
110 | self.marks = marks
111 |
112 | def __add__(self,other):
113 | total_marks = self.marks + other.marks
114 | return Student(f"{self.name} & {other.name}", total_marks)
115 |
116 | def __str__(self):
117 | return f"Name: {self.name}, Marks: {self.marks}"
118 |
119 | student1 = Student("Mark", 85)
120 | student2 = Student("Phoenix", 90)
121 |
122 | combined_student = student1 + student2
123 | print(combined_student)
124 | """
125 |
126 |
--------------------------------------------------------------------------------
/Sets.py:
--------------------------------------------------------------------------------
1 | no_set1 = {1,2,3,4,5}
2 | no_set2 = {4, 5, 6, 7}
3 | m = no_set1 | no_set2
4 | n = no_set1 & no_set2
5 | z = no_set2 - no_set1
6 |
7 | print(m)
8 | print(n)
9 | print(z)
--------------------------------------------------------------------------------
/Tuple.py:
--------------------------------------------------------------------------------
1 | my_tuple = ("Apple", "Berries", "Cherries","Dragon", "Espanol", "Forange")
2 | my_list = list(my_tuple)
3 | num_list = [1, 2, 3, 4]
4 | sting_tuple = ("One", "Two", "Three", "Four")
5 |
6 | # print(my_tuple)
7 | # print(type(my_tuple))
8 | # print(my_list)
9 | """ (A, B, C) = my_tuple
10 | print(A)
11 | print(B)
12 | print(C) """
13 | """" (A, B, *C) = my_tuple
14 | print(A)
15 | print(B)
16 | print(C) """
17 | print(set(zip(num_list, sting_tuple)))
18 |
19 |
--------------------------------------------------------------------------------
/UrlOpen.txt:
--------------------------------------------------------------------------------
1 | b'\n\n
\n \nPhoenix - Wikipedia \n\n\n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\nJump to content \n\n\n\t
\n\t\t
\n\t\t
\n\t\t\t
\n\t\t
\n\t\t\t
\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t
\n\t\t \n\t\t
\n\t
\n\t
\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t
\n\n\t\t\t\t\t
\n\t\t \n\t\t\t
\n\t\t
\n\t\t
\n\t\t\t
\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\n\t
\n\t
\n\nToggle the table of contents \n\t\n\t
\n\n\n\t\t\t\t\t\t\t
\n\t\t\t
\n\t\t\n\t
\n
\n\n\t\t\t\t\t \n\t\t\t\t\tPhoenix \n\t\t\t\t\t\t\t\n\n\t
\n\t
\n\n51 languages \n\t\n\t
\n\n\t\t\n\n\t
\n
\n \n\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\n\n\n\t\t\t\t\t\t\t\t\n\n\t
\n\t
English \n\t\n\t
\n\n\n\t\t\t\t\t\n\n\n\t\t\t\t\n\t
\n
\n\n\t\t\t\t\t\t\t \n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\n\n\n\t\t\t\t\t\t\t \n\t\t\t\t\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\n\n\t
\n\t
Tools \n\t\n\t
\n\n\n\t\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\n
\n\t
\n\t\n\t\n\t\n
\n\n\t\n\n\n\n\n\n\n\n\n
\n\n\t\t\t\t\t\t\t\t\t
\n\t\t\t\t\n\t
\n
\n\n\t\t\t\t\t\t\t \n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\t\t
\n\t\t \n\t\t\t\t\t\t
\n\t\t\t\t\t\t \n\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t
\n\n\t\t\t\t\t\t
From Wikipedia, the free encyclopedia
\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n
Phoenix most often refers to:\n
\n
\n
Phoenix may also refer to:\n
\n
\n
Mythology [ edit ] \n
Greek mythological figures [ edit ] \n
\n
Mythical birds called phoenix [ edit ] \n
Phoenix (mythology) , a mythical bird from Egyptian, Greek, Roman and Persian legends \nEgyptian Bennu \nHindu Garuda and Gandabherunda \nFirebird (Slavic folklore) , in Polish \xc5\xbbar-ptak , Russian Zharptitsa , Serbian \xc5\xbdar ptica , and Slovak Vt\xc3\xa1k Ohniv\xc3\xa1k \nT\xc5\xb1zmad\xc3\xa1r , in Hungarian mythology \nPersian Simurgh , in Arabian Anka , Turkish Z\xc3\xbcmr\xc3\xbcd\xc3\xbc Anka , and Georgian Paskunji \nChinese Fenghuang , in Japanese H\xc5\x8d-\xc5\x8d , Tibetan Me Byi Karmo , Korean Bonghwang , and Vietnamese Ph\xc6\xb0\xe1\xbb\xa3ng (ho\xc3\xa0ng) or Ph\xe1\xbb\xa5ng (ho\xc3\xa0ng) \nEast Asian Vermilion Bird in Chinese Zh\xc5\xab Qu\xc3\xa8 , Japanese Suzaku , Korean Jujak or Bulsajo , and Vietnamese Chu T\xc6\xb0\xe1\xbb\x9bc \nChol (bible) , Milcham , Avarshina , Urshinah or other transliterations of \xd7\x90\xd7\x95\xd7\xa8\xd7\xa9\xd7\x99\xd7\xa0\xd7\x94 \nNine-headed Bird , one of the earliest forms of the Chinese phoenix (Fenghuang)\n
\n
\n
\n
United States [ edit ] \n
Phenix City, Alabama \nPhoenix, Arizona \nPhoenix metropolitan area , Arizona \nPhoenix, Georgia \nPhoenix, Illinois \nPhoenix, Louisiana \nPhoenix, Maryland \nPhoenix, Michigan \nPhoenix, Mississippi \nPhoenix, Edison, New Jersey \nPhoenix, Sayreville, New Jersey \nPhoenix, New York \nPhoenix, Oregon \n
Elsewhere [ edit ] \n
Phoenix (Caria) , a town of ancient Caria, now in Turkey \nPhoenix (Crete) , a town of ancient Crete mentioned in the Bible \nPhoenix (Lycia) , a town of ancient Lycia, now in Turkey \nPhoenix Park , Dublin, Ireland \nPhoenix Islands , in the Republic of Kiribati \nPhoenix, KwaZulu-Natal , in South Africa \nPhoenix City, a nickname for Warsaw , the capital of Poland \nPhoenix, a river of Thessaly, Greece, that flowed at the ancient city of Anthela \n
Arts and entertainment [ edit ] \n
\n
\n
Fictional entities [ edit ] \n
Characters [ edit ] \n
Phoenix (comics) , alias used by several comics characters \nPhoenix Force (comics) , a Marvel Comics entity \nJean Grey , also known as Phoenix and Dark Phoenix, an X-Men character \nRachel Summers , a Marvel Comics character also known as Phoenix \nPhoenix (Transformers ) \nPhoenix Hathaway , a character in the British soap opera Hollyoaks \nPhoenix Raynor , a Shortland Street character \nPhoenix Wright , an Ace Attorney character \nAster Phoenix (or Edo Phoenix), a Yu-Gi-Oh! GX character \nPaul Phoenix (Tekken ) , a Tekken character \nSimon Phoenix , a Demolition Man character \nStefano DiMera , also known as The Phoenix, a Days of our Lives character \nPhoenix, female protagonist of the film Phantom of the Paradise , played by Jessica Harper \nPhoenix Buchanan, a fictional actor and the main antagonist of Paddington 2 \nPhoenix Jackson, female protagonist of "A Worn Path " by Eudora Welty \n
Organizations [ edit ] \n
\n
Vessels [ edit ] \n
\n
\n
\n
Literature [ edit ] \n
\n
\n
\n
\n
Periodicals [ edit ] \n
\n
Other literature [ edit ] \n
\n
\n
Musicians [ edit ] \n
\n
\n
\n
\n
\n
Television [ edit ] \n
\n
Video gaming [ edit ] \n
\n
Other uses in arts and entertainment [ edit ] \n
\n
\n
\n
Business [ edit ] \n
\n
In business, generally:\n
\n
Phoenix company , a commercial entity which has emerged from the collapse of another through insolvency\n
Specific businesses named "Phoenix" include:\n
\n
Airlines [ edit ] \n
\n
Finance companies [ edit ] \n
\n
Media companies [ edit ] \n
\n
Theatres [ edit ] \n
\n
Manufacturers [ edit ] \n
Vehicle manufacturers [ edit ] \n
\n
Other manufacturers [ edit ] \n
Phoenix (nuclear technology company) , specializing in neutron generator technology \nPhoenix AG , a German rubber products company \nPhoenix Beverages , a brewery in Mauritius \nPhoenix Contact , a manufacturer of industrial automation, interconnection, and interface solutions \nPhoenix Iron Works (Phoenixville, Pennsylvania) , owner of the Phoenix Bridge Company \nPhoenix Petroleum Philippines, Inc. , a Philippine oil and gas company\n
Military [ edit ] \n
\n
\n
Phoenix (given name) \nPhoenix (surname) , multiple people \nPhoenix (drag queen) , American drag performer \nDave Farrell (born 1977), American bass guitarist, stage name Phoenix, in the band Linkin Park \nNahshon Even-Chaim (born 1971), or "Phoenix", convicted Australian computer hacker \nJody Fleisch (born 1980), professional wrestler nicknamed "The Phoenix" \nVishnuvardhan (actor) (1950\xe2\x80\x932009), Indian actor, known as the "Phoenix of Indian cinema"\n
Schools [ edit ] \n
\n
Science and technology [ edit ] \n
Astronomy [ edit ] \n
\n
Biology [ edit ] \n
\n
Computing [ edit ] \n
Phoenix (computer) , an IBM mainframe at the University of Cambridge \nPhoenix (tkWWW-based browser) , a web browser and HTML editor discontinued in 1995 \nPhoenix (web framework) , a web development framework \nPhoenix Network Coordinates , used to compute network latency \nPhoenix Object Basic , a RAD tool \nPhoenix Technologies , a BIOS manufacturer \nApache Phoenix , a relational database engine \nMicrosoft Phoenix , a compiler framework \nMozilla Phoenix , the original name for the Firefox web browser \nPhoenix pay system , a payroll processing system\n
Vehicles [ edit ] \n
\n
Phoenix (spacecraft) , a NASA mission to Mars \nAIM-54 Phoenix , a missile \nBAE Systems Phoenix , an unmanned air vehicle \nEADS Phoenix , a prototype launch vehicle \nBristol Phoenix , an aircraft engine \nChrysler Phoenix engine , an automotive engine series \nDodge Dart Phoenix, an American car produced 1960\xe2\x80\x931961 \nDodge Phoenix , Australian car produced 1960\xe2\x80\x931973 \nPontiac Phoenix , an American car produced 1977\xe2\x80\x931984 \nPhoenix Air Phoenix , a Czech glider\n
Other technologies [ edit ] \n
\n
\n
HMS Phoenix , several Royal Navy ships \nPhoenix (East Indiaman) , several ships that sailed for the British East India Company between 1680 and 1821 \nUSS Phoenix , several U.S. Navy ships \nPhoenix , involved in the 1688 Siege of Derry \nPhoenix (1792) , involved in the sea otter trade \nPhoenix (1794) , the first ship built in Russian America \nPhoenix (1798 ship) , made one voyage in 1824 carrying convicts to Tasmania; grounded, condemned, and turned into a prison hulk; broken up in 1837 \nPhoenix (steamboat) , a steamboat built 1806\xe2\x80\x931807 \nPhoenix (1809 ship) , built in France in 1809; captured by the British Royal Navy in 1810; employed as a whaling ship from 1811 to 1829 \nPhoenix (1810 ship) , a merchant vessel launched in 1810; made one voyage to India for the British East India Company; made three voyages transporting convicts to Australia; wrecked in 1829 \nPhoenix (1815 steamer) , a steamboat that burned on Lake Champlain in 1819; its wreck is a Vermont state historic site \nPhoenix (1821 whaler) , a Nantucket whaling vessel in operation 1821\xe2\x80\x931858 \nPhoenix (1845) , a steamship that burned on Lake Michigan in 1847 with the loss of at least 190 lives \nUSCS Phoenix , a U.S. Coast Survey ship in service from 1845 to 1858 \nSS Ph\xc3\xb6nix (1913) , a German cargo ship which later saw service as the vorpostenboot V-106 Ph\xc3\xb6nix \nPhoenix (1929 ship) , a Danish ship built in 1929 \nSS Flying Lark , which went by the name Phoenix from 1946 to 1948 \nPhoenix (fireboat) , a 1955 fireboat operating in San Francisco, California \nPhoenix (1973) , a rescue vessel used to save migrants, refugees and other people in distress in the Mediterranean Sea\n
\n
\n
Other uses [ edit ] \n
\n
See also [ edit ] \n
\n
\n
Topics referred to by the same term
\n\n
\n\n\n\n\n
\n
\n\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t \n\t\t\t\n\t\t
\n\t\t\n\t
\n
\n\n\t
\n\t\t\n\t\t \n\nToggle limited content width \n \n \n\t \n
\n\n\n\n'
--------------------------------------------------------------------------------
/__pycache__/mod.cpython-312.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ArjiJethin/Python-Basic/849284ae443ff7d05763a5080c5e352031c3808e/__pycache__/mod.cpython-312.pyc
--------------------------------------------------------------------------------
/bin.txt:
--------------------------------------------------------------------------------
1 | Hello World
2 | This is my programme
3 | Hehe
4 | :)
5 | Malevolent Shrine
6 | Malignant Blaze
7 | Damn this is damn in damn damn damn
--------------------------------------------------------------------------------
/copy.txt:
--------------------------------------------------------------------------------
1 | Hello World
2 | This is my programme
3 | Hehe
4 | :)
5 | Malevolent Shrine
6 | Malignant Blaze
7 | Damn this is damn in damn damn damn
--------------------------------------------------------------------------------
/mod.py:
--------------------------------------------------------------------------------
1 | def add(x,y):
2 | return x+y
--------------------------------------------------------------------------------
/revision 2.py:
--------------------------------------------------------------------------------
1 | """
2 | with open("Text.txt", "r") as f1:
3 | with open("copy.txt", "w") as f2:
4 | for line in f1:
5 | f2.write(line)
6 |
7 | print("Contents have been written :)")
8 | """
9 |
10 | """
11 | import urllib.request
12 | url = "https://en.wikipedia.org/wiki/Phoenix"
13 | headers = {}
14 | Request = urllib.request.Request(url, headers = headers)
15 | Response = urllib.request.urlopen(Request)
16 | Data = Response.read()
17 | with open("UrlOpen.txt", "w") as f:
18 | f.write(str(Data))
19 | print("Contents Written! :)")
20 | """
21 |
22 | def count_word_frequency(filename):
23 | word_frequency = {}
24 | with open(filename, "r") as f:
25 | for line in f:
26 | words = line.split()
27 | for word in words:
28 | word = word.strip("?,:!")
29 | if word:
30 | word_frequency[word] = word_frequency.get(word,0)+1
31 |
32 | print("Word Frequency:-")
33 | for word, frequency in word_frequency.items():
34 | print(f"{word} : {frequency}")
35 |
36 |
37 | def main():
38 | filename = input("Enter filename: ")
39 | count_word_frequency(filename)
40 |
41 |
42 | if __name__ == "__main__":
43 | main()
44 |
45 |
--------------------------------------------------------------------------------
/revision 3.py:
--------------------------------------------------------------------------------
1 | """
2 | import urllib.request
3 | url = "https://en.wikipedia.org/wiki/Phoenix"
4 | headers = {}
5 | Request = urllib.request.Request(url, headers=headers)
6 | Response = urllib.request.urlopen(Request)
7 | Data = Response.read()
8 | with open("UrlOpen.txt", "w") as f:
9 | f.write(str(Data))
10 | print("Contents Written")
11 | """
12 |
13 | """
14 | def count_word_frequency(filename):
15 | word_frequency = {}
16 | with open(filename, "r") as f:
17 | for line in f:
18 | words = line.split()
19 | for word in words:
20 | word = word.strip("?.,!")
21 | if word:
22 | word_frequency[word] = word_frequency.get(word,0)+1
23 | print("Word Frequency:-")
24 | for word, frequency in word_frequency.items():
25 | print(f" {word} : {frequency}")
26 |
27 | def main():
28 | filename = input("Enter Filename: ")
29 | count_word_frequency(filename)
30 |
31 | if __name__ == "__main__":
32 | main()
33 | """
34 |
35 | def list_methods_demo():
36 | my_list = [1,2,3,4]
37 | my_list.append(5)
38 | print(f"Appended List: {my_list}")
39 | my_list.extend([5,6])
40 | print(f"Extended List = {my_list}")
41 | my_list.insert(0,0)
42 | print(f"Inserted List: {my_list}")
43 | my_list.remove(6)
44 | print(f"Removed List: {my_list}")
45 | popped_element = my_list.pop(-1)
46 | print(f"Popped element: {popped_element}")
47 |
48 | def tuple_methods_demo():
49 | my_tuple = (1,2,3,4)
50 | index = my_tuple.index(4)
51 | print(f"Index of the number of 4: {index}")
52 | count = my_tuple.count(3)
53 | print(f"Count of element 3: {count}")
54 |
55 | def set_methods_demo():
56 | my_set = {1,2,3,4,5}
57 | my_set.add(6)
58 | print("Added Set: ", my_set)
59 | my_set.remove(6)
60 | print("removed Set = ", my_set)
61 | popped_element = my_set.pop()
62 | print(f"The popped element is {popped_element}")
63 |
64 | def dictionary_methods_demo():
65 | my_dict = {'a':1, 'b':2, 'c':3}
66 | value = my_dict.get('c')
67 | print(f"Value of 'c': {value}")
68 | my_dict.update({'d':4})
69 | print(my_dict)
70 | popped_value = my_dict.pop('d')
71 | print(f"Popped Value: {popped_value}")
72 |
73 | def main():
74 | print("List Methods:- ")
75 | list_methods_demo()
76 | print("\nTuple Methods:-")
77 | tuple_methods_demo()
78 | print("\nSet Methods:-")
79 | set_methods_demo()
80 | print("\nDictionary Methods:-")
81 | dictionary_methods_demo()
82 |
83 |
84 | if __name__ == "__main__":
85 | main()
86 |
--------------------------------------------------------------------------------
/revision.py:
--------------------------------------------------------------------------------
1 | # ----------------------------------------------------------- Question 1B ------------------------------------------------------------------------
2 |
3 | """
4 | qty = float(input("Enter the amount of items sold: "))
5 | val = float(input("Enter the value of item: "))
6 | discount = float(input("Enter the discount percentage: "))
7 | tax = float(input("Enter the tax: "))
8 | amt = qty*val
9 | disc_amt = (amt*discount)/100
10 | sub_total = amt - disc_amt
11 | tax_amt = (sub_total*tax)/100
12 | total_amt = sub_total+tax_amt
13 | print("******************************BILL********************************")
14 | print(f"Quantity Sold:\t {qty}")
15 | print(f"Price per item:\t {val}")
16 | print("\t\t-----------------------------------------")
17 | print(f"Amount: \t{amt}")
18 | print(f"Discount amt: \t {disc_amt}")
19 | print("\t\t-------------------------------------------")
20 | print(f"Discounted Total: \t {sub_total}")
21 | print(f"Tax: \t{tax_amt}")
22 | print("\t\t-------------------------------------------")
23 | print(f"Total Amount: \t {total_amt}")
24 | """
25 | # ----------------------------------------------------------- Question 2A ------------------------------------------------------------------------
26 |
27 | """
28 | a = int(input("Enter the coefficient- 'a' : "))
29 | b = int(input("Enter the coefficient- 'a' : "))
30 | c = int(input("Enter the coefficient- 'a' : "))
31 | D = b**2 - (4*a*c)
32 | deno = 2*a
33 |
34 | if D > 0:
35 | print("Real and Unique Roots:-")
36 | R1 = (-b + D**0.5)/(2*a)
37 | R2 = (-b - D**0.5)/(2*a)
38 | print(f"Root 1: '{R1}', Root 2: '{R2}' ")
39 | elif D == 0:
40 | print("Real and Equal Roots")
41 | R = -b/(2*a)
42 | print(f"The roots are {R} & {R}")
43 | else:
44 | print("Imaginary Roots:-")
45 | D = D - (2*D)
46 | Real = -b/(2*a)
47 | Img = D**0.5/(2*a)
48 | print(f" Root 1: '{Real}+{Img}i & Root 2: '{Real} - {Img}''")
49 | """
50 |
51 | # ----------------------------------------------------------- Question 2B ------------------------------------------------------------------------
52 |
53 | """"
54 | n = int(input("Enter a number: "))
55 | sum = 0
56 | for i in range(1,n+1):
57 | if i % 2 == 0:
58 | term = i**2
59 | else:
60 | term = 0
61 | sum += term
62 | print(f"Sum = {sum}")
63 | """
64 |
65 | # ----------------------------------------------------------- Question 3A ------------------------------------------------------------------------
66 |
67 | """
68 | def increment(y):
69 | return (lambda x: x+1)(y)
70 |
71 |
72 | n = int(input("Enter a number: "))
73 | print(f"Number before incrementing: {n}")
74 | n = increment(n)
75 | print(f"Number after incrementing: {n}")
76 | """
77 |
78 | # ----------------------------------------------------------- Question 3B ------------------------------------------------------------------------
79 |
80 | """
81 | from mod import add
82 | a = int(input("Enter a: "))
83 | b = int(input("Enter b: "))
84 | result = add(a,b)
85 | print(f"Result = {result}")
86 | """
87 |
88 | # ----------------------------------------------------------- Question 4A ------------------------------------------------------------------------
89 |
90 | """
91 | message = input("Enter a string: ")
92 | key = int(input("Enter a number: "))
93 | index = 0
94 | while index < len(message):
95 | letter = message[index]
96 | print(chr(ord(letter)+key), end="")
97 | index += 1
98 | """
99 |
100 | # ----------------------------------------------------------- Question 4B ------------------------------------------------------------------------
101 |
102 | """
103 | while 1:
104 | name = input("Enter your name: ")
105 | if not name.isalpha():
106 | print("Invalid Name, please try a gain :(")
107 | else:
108 | break
109 | while 1:
110 | pan_card_no = input("Enter your Pan Card No: ")
111 | if not name.isalnum():
112 | print("Invalid PAN No. , please try a gain :(")
113 | else:
114 | break
115 | print(f"Please Check, Name: {name} & Pan Card No: {pan_card_no}")
116 | """
117 |
118 | # ----------------------------------------------------------- Question 5A ------------------------------------------------------------------------
119 |
120 | """
121 | with open("text.txt", "r") as f1:
122 | with open("copy.txt", "w") as f2:
123 | for line in f1:
124 | f2.write(line)
125 |
126 | print("Contents have been copied")
127 | """
128 |
129 | # ----------------------------------------------------------- Question 5B ------------------------------------------------------------------------
130 |
131 | """
132 | import urllib.request
133 | url = "https://en.wikipedia.org/wiki/Phoenix"
134 | headers = {}
135 | Request = urllib.request.Request(url, headers=headers)
136 | Response = urllib.request.urlopen(Request)
137 | Data = Response.read()
138 | with open("UrlOpen.txt", "w") as f:
139 | f.write(str(Data))
140 | print("Contents written :)")
141 | """
142 |
143 | # ----------------------------------------------------------- Question 6A ------------------------------------------------------------------------
144 |
145 | """
146 | def count_word_frequency(filename):
147 | word_frequency = {}
148 | with open(filename, "r") as f:
149 | for line in f:
150 | words = line.split()
151 | for word in words:
152 | word = word.strip(".,?!")
153 | if word:
154 | word_frequency[word] = word_frequency.get(word, 0)+1
155 | print("Word Frequency:-")
156 | for word, frequency in word_frequency.items():
157 | print(f" {word} : {frequency}")
158 |
159 | def main():
160 | filename = input("Enter filename: ")
161 | count_word_frequency(filename)
162 |
163 |
164 | if __name__ == "__main__":
165 | main()
166 | """
167 |
168 | # ----------------------------------------------------------- Question 6A ------------------------------------------------------------------------
169 |
170 | def list_methods_demo():
171 | my_list = [1, 2, 3, 4]
172 | my_list.append(5)
173 | print(f"Appended List = {my_list}")
174 | my_list.extend([5,6,7])
175 | print(f"Extended List = {my_list}")
176 | my_list.insert(0,0)
177 | print(f"Inserted List: {my_list}")
178 | my_list.remove(7)
179 | print(f"Removed List = {my_list}")
180 | popped_element = my_list.pop(-1)
181 | print(f"Popped Element = {popped_element}")
182 |
183 | def tuple_methods_demo():
184 | my_tuple = (1,2,3,4)
185 | index = my_tuple.index(3)
186 | print(f"Index of the number 3: {index}")
187 | count = my_tuple.count(4)
188 | print(f"Count of element 4: {count}")
189 |
190 | def set_methods_demo():
191 | my_set = {1,2,3,4,5}
192 | my_set.add(6)
193 | print(f"Added Set: {my_set}")
194 | my_set.remove(6)
195 | print(f"Removed Set: {my_set}")
196 | popped_element = my_set.pop()
197 | print(f"Popped Element: {popped_element}")
198 |
199 | def dictionary_methods_demo():
200 | my_dict = {'a':1, 'b':2, 'c':3}
201 | value = my_dict.get('b')
202 | print(f"Value of b: {value}")
203 | my_dict.update({'d':4})
204 | print(f"Updated Dictionary: {my_dict}")
205 | popped_value = my_dict.pop('d')
206 | print(f"The popped value: {popped_value}")
207 |
208 | def main():
209 | print("List Methods:-")
210 | list_methods_demo()
211 | print("\nTuple Methods:-")
212 | tuple_methods_demo()
213 | print("\nSet Methods:-")
214 | set_methods_demo()
215 | print("\nDictionary Methods:-")
216 | dictionary_methods_demo()
217 |
218 |
219 | if __name__ == "__main__":
220 | main()
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
--------------------------------------------------------------------------------
/text.txt:
--------------------------------------------------------------------------------
1 | Hello World
2 | This is my programme
3 | Hehe
4 | :)
5 | Malevolent Shrine
6 | Malignant Blaze
7 | Damn this is damn in damn damn damn
--------------------------------------------------------------------------------