Skip to content

Commit 428a67c

Browse files
authored
Add files via upload
1 parent 4cae52e commit 428a67c

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"8960 Candida - Practical 3.ipynb","provenance":[],"collapsed_sections":[],"mount_file_id":"14q0TyBfW7gvJPrJBMwZow8BuKb6HaIi9","authorship_tag":"ABX9TyPYv+sl7r1FezpRlq/p6M6+"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","metadata":{"id":"g9gyUyiP5zeX"},"source":["**Name : Candida Ruth Noronha**\n","\n","**Class : SE COMPS B**\n","\n","**Roll No. : 8960**\n","\n","**Title : Python Experiment 3**"]},{"cell_type":"markdown","metadata":{"id":"oSOcPHip9-Zv"},"source":["**Aim: Write python programs to understand different file handling operations.**\n","1. Write a python program which will count the spaces, tabs, and lines in any given text file. \n","Check if the file exists. If file does not exists then handle that exception.\n","\n","**Code :**\n"]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"UQpp0LuRFLZB","executionInfo":{"status":"ok","timestamp":1618214218006,"user_tz":-330,"elapsed":33552,"user":{"displayName":"8960 Candida Noronha","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14Gh9oFSqr_U0fh4PF3gsP-c3esjIdm_OM-IMv4go=s64","userId":"03185904400426411648"}},"outputId":"8025189b-a9c0-466f-d0e1-cf917f8eb565"},"source":["from google.colab import drive\n","drive.mount('/content/drive')"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Mounted at /content/drive\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"dD4qCDk65aWZ","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1618218546616,"user_tz":-330,"elapsed":965,"user":{"displayName":"8960 Candida Noronha","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14Gh9oFSqr_U0fh4PF3gsP-c3esjIdm_OM-IMv4go=s64","userId":"03185904400426411648"}},"outputId":"ce1600c2-daf4-477f-a383-d9168b5baf4c"},"source":["from collections import Counter\n","try:\n"," with open(\"drive/MyDrive/8960_Candida_Python/Practical 3/content.txt\") as f:\n"," text = f.read()\n"," count = Counter(text)\n","except:\n"," print(\"File not Found\")\n","else:\n"," spaces = count[\" \"]\n"," tabs = count[\"\\t\"]\n"," lines = count[\"\\n\"]\n"," print(\"The total number of spaces present in this file is \", spaces)\n"," print(\"The total number of tabs present in this file is \", tabs)\n"," print(\"The total number of lines present in this file is \", lines)\n"],"execution_count":null,"outputs":[{"output_type":"stream","text":["The total number of spaces present in this file is 114\n","The total number of tabs present in this file is 5\n","The total number of lines present in this file is 6\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"jHLXtoLOGjCK"},"source":["2. The file cities_and_times.txt contains city names and times.\n","Each line contains the name of the city, followed by the name of the day (\"Sun\") and the time in the form hh:mm. \n","Read in the file and create an alphabetically ordered list of the form\n","\n","[('Amsterdam', 'Sun', (8, 52)), ('Anchorage', 'Sat', (23, 52)), ('Ankara', 'Sun', (10, \n","52)), ('Athens', 'Sun', (9, 52)), ('Atlanta', 'Sun', (2, 52)), ('Auckland', 'Sun', (20, 52)), \n","('Barcelona', 'Sun', (8, 52)), ('Beirut', 'Sun', (9, 52)), \n","...\n","….\n","('Toronto', 'Sun', (2, 52)), ('Vancouver', 'Sun', (0, 52)), ('Vienna', 'Sun', (8, 52)), \n","('Warsaw', 'Sun', (8, 52)), ('Washington DC', 'Sun', (2, 52)), ('Winnipeg', 'Sun', (1, \n","52)), ('Zurich', 'Sun', (8, 52))]\n","Finally, the list should be dumped for later usage with the pickle module.\n","\n","**Code :**"]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"add9lNLbac1n","executionInfo":{"status":"ok","timestamp":1618467222507,"user_tz":-330,"elapsed":3940,"user":{"displayName":"8960 Candida Noronha","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14Gh9oFSqr_U0fh4PF3gsP-c3esjIdm_OM-IMv4go=s64","userId":"03185904400426411648"}},"outputId":"3f6cb044-f3ac-4877-ee9c-467aff538708"},"source":["import pickle\n","l=[tuple(line.strip().split(\" \")) for line in open(\"drive/MyDrive/8960_Candida_Python/Practical 3/cities_and_times.txt\")]\n","l.sort()\n","dump=open(\"drive/MyDrive/8960_Candida_Python/Practical 3/dump\",\"wb\")\n","pickle.dump(l,dump)\n","dump.close()\n","\n","load=open(\"drive/MyDrive/8960_Candida_Python/Practical 3/dump\",\"rb\")\n","print(*pickle.load(load) , sep = '\\n')"],"execution_count":1,"outputs":[{"output_type":"stream","text":["('Amsterdam', 'Sun', '08:52')\n","('Anchorage', 'Sat', '23:52')\n","('Ankara', 'Sun', '10:52')\n","('Athens', 'Sun', '09:52')\n","('Atlanta', 'Sun', '02:52')\n","('Auckland', 'Sun', '20:52')\n","('Barcelona', 'Sun', '08:52')\n","('Beirut', 'Sun', '09:52')\n","('Berlin', 'Sun', '08:52')\n","('Boston', 'Sun', '02:52')\n","('Brasilia', 'Sun', '05:52')\n","('Brussels', 'Sun', '08:52')\n","('Bucharest', 'Sun', '09:52')\n","('Budapest', 'Sun', '08:52')\n","('Cairo', 'Sun', '09:52')\n","('Calgary', 'Sun', '01:52')\n","('Cape', 'Town', 'Sun', '09:52')\n","('Casablanca', 'Sun', '07:52')\n","('Chicago', 'Sun', '01:52')\n","('Columbus', 'Sun', '02:52')\n","('Copenhagen', 'Sun', '08:52')\n","('Dallas', 'Sun', '01:52')\n","('Denver', 'Sun', '01:52')\n","('Detroit', 'Sun', '02:52')\n","('Dubai', 'Sun', '11:52')\n","('Dublin', 'Sun', '07:52')\n","('Edmonton', 'Sun', '01:52')\n","('Frankfurt', 'Sun', '08:52')\n","('Halifax', 'Sun', '03:52')\n","('Helsinki', 'Sun', '09:52')\n","('Houston', 'Sun', '01:52')\n","('Indianapolis', 'Sun', '02:52')\n","('Istanbul', 'Sun', '10:52')\n","('Jerusalem', 'Sun', '09:52')\n","('Johannesburg', 'Sun', '09:52')\n","('Kathmandu', 'Sun', '13:37')\n","('Kuwait', 'City', 'Sun', '10:52')\n","('Las', 'Vegas', 'Sun', '00:52')\n","('Lisbon', 'Sun', '07:52')\n","('London', 'Sun', '07:52')\n","('Los', 'Angeles', 'Sun', '00:52')\n","('Madrid', 'Sun', '08:52')\n","('Melbourne', 'Sun', '18:52')\n","('Miami', 'Sun', '02:52')\n","('Minneapolis', 'Sun', '01:52')\n","('Montreal', 'Sun', '02:52')\n","('Moscow', 'Sun', '10:52')\n","('New', 'Orleans', 'Sun', '01:52')\n","('New', 'York', 'Sun', '02:52')\n","('Oslo', 'Sun', '08:52')\n","('Ottawa', 'Sun', '02:52')\n","('Paris', 'Sun', '08:52')\n","('Philadelphia', 'Sun', '02:52')\n","('Phoenix', 'Sun', '00:52')\n","('Prague', 'Sun', '08:52')\n","('Reykjavik', 'Sun', '07:52')\n","('Riyadh', 'Sun', '10:52')\n","('Rome', 'Sun', '08:52')\n","('Salt', 'Lake', 'City', 'Sun', '01:52')\n","('San', 'Francisco', 'Sun', '00:52')\n","('San', 'Salvador', 'Sun', '01:52')\n","('Santiago', 'Sun', '04:52')\n","('Seattle', 'Sun', '00:52')\n","('Shanghai', 'Sun', '15:52')\n","('Singapore', 'Sun', '15:52')\n","('Stockholm', 'Sun', '08:52')\n","('Sydney', 'Sun', '18:52')\n","('São', 'Paulo', 'Sun', '05:52')\n","('Tokyo', 'Sun', '16:52')\n","('Toronto', 'Sun', '02:52')\n","('Vancouver', 'Sun', '00:52')\n","('Vienna', 'Sun', '08:52')\n","('Warsaw', 'Sun', '08:52')\n","('Washington', 'DC', 'Sun', '02:52')\n","('Winnipeg', 'Sun', '01:52')\n","('Zurich', 'Sun', '08:52')\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"FsFyUoxch2Uu"},"source":["**Post Labs**"]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"HdxhXzglh4so","executionInfo":{"status":"ok","timestamp":1618222160746,"user_tz":-330,"elapsed":1343,"user":{"displayName":"8960 Candida Noronha","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14Gh9oFSqr_U0fh4PF3gsP-c3esjIdm_OM-IMv4go=s64","userId":"03185904400426411648"}},"outputId":"90601531-a4be-41e1-c972-1095878370ad"},"source":["def longestword(filename):\n"," with open(\"drive/MyDrive/8960_Candida_Python/Practical 3/computer.txt\") as f:\n"," words = f.read().split()\n"," max_len_word = max(words,key=len)\n"," max_len = len(max(words,key=len))\n"," print('The word in the file with maximum length is :',max_len_word)\n"," print('And its length is : ',max_len)\n","longestword(\"text.txt\")"],"execution_count":null,"outputs":[{"output_type":"stream","text":["The word in the file with maximum length is : automatically.\n","And its length is : 14\n"],"name":"stdout"}]}]}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
Chicago Sun 01:52
2+
Columbus Sun 02:52
3+
Riyadh Sun 10:52
4+
Copenhagen Sun 08:52
5+
Kuwait City Sun 10:52
6+
Rome Sun 08:52
7+
Dallas Sun 01:52
8+
Salt Lake City Sun 01:52
9+
San Francisco Sun 00:52
10+
Amsterdam Sun 08:52
11+
Denver Sun 01:52
12+
San Salvador Sun 01:52
13+
Detroit Sun 02:52
14+
Las Vegas Sun 00:52
15+
Santiago Sun 04:52
16+
Anchorage Sat 23:52
17+
Ankara Sun 10:52
18+
Lisbon Sun 07:52
19+
São Paulo Sun 05:52
20+
Dubai Sun 11:52
21+
London Sun 07:52
22+
Seattle Sun 00:52
23+
Dublin Sun 07:52
24+
Los Angeles Sun 00:52
25+
Athens Sun 09:52
26+
Edmonton Sun 01:52
27+
Madrid Sun 08:52
28+
Shanghai Sun 15:52
29+
Atlanta Sun 02:52
30+
Frankfurt Sun 08:52
31+
Singapore Sun 15:52
32+
Auckland Sun 20:52
33+
Halifax Sun 03:52
34+
Melbourne Sun 18:52
35+
Stockholm Sun 08:52
36+
Barcelona Sun 08:52
37+
Miami Sun 02:52
38+
Minneapolis Sun 01:52
39+
Sydney Sun 18:52
40+
Beirut Sun 09:52
41+
Helsinki Sun 09:52
42+
Montreal Sun 02:52
43+
Berlin Sun 08:52
44+
Houston Sun 01:52
45+
Moscow Sun 10:52
46+
Indianapolis Sun 02:52
47+
Boston Sun 02:52
48+
Tokyo Sun 16:52
49+
Brasilia Sun 05:52
50+
Istanbul Sun 10:52
51+
Toronto Sun 02:52
52+
Vancouver Sun 00:52
53+
Brussels Sun 08:52
54+
Jerusalem Sun 09:52
55+
New Orleans Sun 01:52
56+
Vienna Sun 08:52
57+
Bucharest Sun 09:52
58+
Johannesburg Sun 09:52
59+
New York Sun 02:52
60+
Warsaw Sun 08:52
61+
Budapest Sun 08:52
62+
Oslo Sun 08:52
63+
Washington DC Sun 02:52
64+
Ottawa Sun 02:52
65+
Winnipeg Sun 01:52
66+
Cairo Sun 09:52
67+
Paris Sun 08:52
68+
Calgary Sun 01:52
69+
Kathmandu Sun 13:37
70+
Philadelphia Sun 02:52
71+
Zurich Sun 08:52
72+
Cape Town Sun 09:52
73+
Phoenix Sun 00:52
74+
Prague Sun 08:52
75+
Casablanca Sun 07:52
76+
Reykjavik Sun 07:52
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations automatically. Modern computers can perform generic sets of operations known as programs. These programs enable computers to perform a wide range of tasks. A computer system is a "complete" computer that includes the hardware, operating system (main software), and peripheral equipment needed and used for "full" operation. This term may also refer to a group of computers that are linked and function together, such as a computer network or computer cluster.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Christmas (or the Feast of the Nativity)[not verified in body] is an annual festival commemorating the birth of Jesus Christ, observed primarily on December 25[a] as a religious and cultural celebration by billions of people around the world.
2+
3+
A feast central to the Christian liturgical year, it is preceded by the season of Advent or the Nativity Fast and initiates the season of Christmastide, which historically in the West lasts twelve days and culminates on Twelfth Night.
4+
5+
Christmas Day is a public holiday in many of the world's nations, is celebrated religiously by a majority of Christians, as well as culturally by many non-Christians, and forms an integral part of the holiday season centered around it.
6+

8960 Candida - Practical 3/dump

3.23 KB
Binary file not shown.

0 commit comments

Comments
 (0)