0% found this document useful (0 votes)
77 views27 pages

400 Python Exercise

This document contains more than 400 Python programming exercises organized by topics such as: file management, conditionals, loops, functions, text strings, lists, dictionaries, among others. The exercises range from basic to more advanced and are designed for the reader to practice and improve their programming skills through continuous problem solving.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
77 views27 pages

400 Python Exercise

This document contains more than 400 Python programming exercises organized by topics such as: file management, conditionals, loops, functions, text strings, lists, dictionaries, among others. The exercises range from basic to more advanced and are designed for the reader to practice and improve their programming skills through continuous problem solving.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 27

Skip to main content

MENTIONS

ANALYTICS

UPLOAD

TOOLS

Premium
15
Jorge
Download PDF

Full PDF Package

Translate PDF
More than 400 Python programming exercises

Paola Ortiz

Top 0.1%269721 Views48 Pages


1 File ▾

Learn to think like a programmer with continuous exercise with


the problems presented in the document

Download PDF

Full PDF Package


Translate PDF
Original PDF

Summary
Related

2003/11/26-16:57
·
465
Make a program that reads a text file that may contain stressed vowels and
displays a version of the file in which each stressed vowel has been replaced by
the same unstressed vowel.
·
466
Design a program,
decrypt.py
, which decrypts files encrypted by
cipher.py
. The program will ask for the name of the encrypted file and the name of the
file in which the result will be saved.
·
467
Design a program that, given two text files, tells us if the first is an encrypted version of
the second (with the encryption code described in the section).
·
468
Design a program that obtains the first 100 prime numbers and stores them in a text file
called
cousins.txt
.
·
469
Make a program that asks for the name of a Unix user group. Next, open a file
in writing mode with the same name as the read group and extension
grp
. In this file you must write the real name of all the users in said group, one on
each line. (Read the statement of exercises 461 and 463 first.)
·
470
We want to automate the sending of personalized email to our clients. (Do you remember
the section
??
?If not, study it again.) We have a client file called
clients.txt
in which each line has the email address and name of a client of ours. The file starts like this:
1
al00000@alumail.uji.esPedroP´erez
2
spammer@spam.comJohnDoe
3
...
In another file, called
letter.txt
, we have a customizable menu. In it, the place where we want to put the
client's name appears marked with the text
$CLIENT$
. The letter begins like this:
1
Dear Mr/Mr/a$CLIENT$:
23
We have news that you, a $CLIENT$, have not paid the amount
4
of the monthly fee required by the draconian contract he signed
5
...
Make a program that sends an email to each client with the content of
letter.txt
duly personalized. Now that you know how to define and use functions, design the
program using them.
·
471
Our files
clients.txt
It is now modified to include the sex of the person as the second field on each
line. The letter
h
indicates that it is a man and the letter
M
that it is a woman. Modify the program so that it replaces the
expressions
don/do~na
by
Don
either
don~na
,
Dear
by
Dear
either
Dear
and
Mrs
by
Mr
either
Mrs
as required.
·
472
We have decided to replace the three calls to the method
write
of lines 32, 33 and 34 by a single one:
fcopy
.
write
(
line
1
+
line
2
+
line
3
)
Will it work the same?
·
473
In its current version, it is possible to add the same entry to the calendar
twice. Modify
anyadir
_
entrance
so that it only adds a new entry if it corresponds to a different person. Adding data for the
same person for the second time means replacing the old phone with the new one.
·
474
Adds the following operations to the calendar: Complete listing of the calendar on the
screen. Each entry must occupy a single line on the screen. Telephone list of all people
whose last name begins with a specific letter.
·
475
Make sure that every time an entry is added to the agenda, it is ordered
alphabetically.
·
476
We want to be able to work with more than one phone per person. Modify the
phonebook program so that the line containing the telephone contains a list of
telephones separated by blanks. Here is an example of input with three phones:
1
Pedro

2
L'opez

3
96411253796400992396411092

The function
look for
_
entrance
will return a list with as many elements as there are telephone numbers of the person found. Enrich the
application with the possibility of deleting one of a person's phones.
46
Introduction to Programming with Python
c

2003 Andr'es Marzal and Isabel Gracia
·
477
Modify the student management application from the previous chapter so that it
remembers all data between runs. (You can be inspired by the second version of the
agenda.)
·
478
Modify the video store management application from the previous chapter so that it
remembers all data between runs. Maintain two different files: one for the films and another
for the partners.
·
479
Design a program that reads a text file in HTML format and generates another in which all
the text fragments highlighted in bold are replaced by the same text highlighted in italics.
·
480
The headers (chapter titles, sections, subsections, etc.) of a page
Web
They are marked by enclosing them between
<H
n
>
and
</H
n
>
, where
n
is a number between 1 and 6 (the main or level 1 header is enclosed
in
<H1>
and
</H1>
). Write a program for each of these tasks on an HTML file: display only the
text of the level 1 headers; display the text of all the headers, but with
indentation, so that the text of the level 1 headers
n
spaces appearing further to the right than the level headers
n

1.An example of use of the second program will help you understand what is requested. For
the following HTML file,
1
<HTML>
2
<BODY>
3
<H1>One owner</H1>
4
<P>Text in a paragraph.
5
<P>Another paragraph.
6
<H1>Other owner</H1>
7
<H2>Asubtitle</H2>
8
<P>Andyourtext.
9
<H3>Asubsubtitle</H3>
10
<H2>Anothersubtitle</H2>
11
<P>Andhis
12
</BODY>
13
</HTML>
The program will display on the screen:
A headlineAnother headlineA subtitleA subsubtitleAnother subtitle
·
481
Add an option to the agenda developed in the previous section to generate a file
agenda.html
with a dump of the agenda that we can view in a browser
Web
. The list will appear alphabetically ordered (by last name), with a section for
each letter of the alphabet and one line per entry. The last name of each person
will appear highlighted in bold.
·
482
Modify the program
agenda2.py
so that it assumes a format of
agenda.txt
similar to
/etc/passwd
.Eachlinecontainsoneentryandeachentryconsistsof3ormorefieldsseparatedbyacolon.Thefirstfieldisthename,thesecondisthelastnameandthe
thirdandsubsequentfieldscorrespondtodifferenttelephonenumbersofthatperson.
·
483
A program is, at its core, a formatted text file, although quite
complicated, as a general rule. When you run a program the
interpreter is, pardon the redundancy, interpreting its meaning step by
step. We are going to design ourselves an interpreter for a small
programming language. The language only has three variables called
TO
,
b
and
c
. You can assign a value to a variable with statements like those in this
program:
1
assigns A sum 3 and 7
2
assign B subtract A and 2
3
assigns C product A and B
4
assignsAdivisionAy10
If you play that show,
TO
ends up being worth 1,
b
ends up being worth 8 and
c
It ends up being worth 80. The other language statement allows the value of a
variable to be displayed on the screen. If you add these other sentences to the
previous program:
1
sampleA
2
sampleB
Introduction to Programming with Python
47
2003/11/26-16:57
You will get on the screen a line with the value 1 and another with the value 8. Design a
program that asks for the name of a text file that contains sentences from our language and
displays the result of its execution on the screen. . If the program encounters an incorrectly
written statement (for example
showmeA
), will stop displaying the line number where it found the error.
·
484
Enrich the interpreter of the previous exercise so that he understands the order
Yeah
value condition value
thenline
number
. In her,
worth
It can be a number or a variable and
condition
could be the word
equal
or the word
distinct
. The statement is interpreted as if the condition is true, the next line to be executed is the
one with the number
number
.If your Python program interprets this program:
1
assigns to sums 0 and 1
2
assignsBsums0and1
3
sampleB
4
assignsBproduct2andB
5
assigns A adds A and 1
6
if A different 8 then line 3
will appear on the screen
1248163264
48
Introduction to Programming with Python
ABOUT AUTHOR

Paola Ortiz
University of Cuenca, Ecuador
Alumnus
PAPERS
1
FOLLOWERS
14.009
Follow
RELATED PAPERS
Exercises-python
NAKED PLANET
DownloadMore Options
python exercises
perick van der vhir
DownloadMore Options

More_de_400_ejercicios_de_programacion_en.pdf
Neslon thin red
DownloadMore Options

ippython
manuel valenzuela
DownloadMore Options

Python
Alfredo Pinedo Aparicio
DownloadMore Options
python s
Salvador Mtz
DownloadMore Options

Introduction to Python
Nacho Ventura
DownloadMore Options

Python book
Rommel Rios Alcantara
DownloadMore Options

Introduction to Python programming FREELIBROS COM


Claudio Castillo
DownloadMore Options
Introduction to programming with Python
dani barbal
DownloadMore Options

Introduction to programming in Python


Nico Juarez
DownloadMore Options

Python Course
Sergio Camacho
DownloadMore Options

C PDF Book
David Asencio
DownloadMore Options
Introduction to programming with C
Jose Luis
DownloadMore Options

Python -Class Guide


Pedro Muñoz del Rio
DownloadMore Options

Python for Computer Scientists Exploring Information Charles Severance


Jorge Lara
DownloadMore Options

Python by vilar
Exxo Music
DownloadMore Options
Python: Basics and exercises
Fran Molina Sánchez
DownloadMore Options

Python by vilar exercises


Neido Garcia
DownloadMore Options

Snake Taming for Kids - Learning to Program with Python


YiMmy Motta
DownloadMore Options

Learn to Think Like a Programmer with Python


Alexander Lambrecht
DownloadMore Options
Learn to program with Python
William Glaffo
DownloadMore Options

Learn to Think Like a Programmer


Rolo Velasquez
DownloadMore Options

Think Python esp


pepa zuñiga
DownloadMore Options

Learn to think like programming with python


Eyder Castellar
DownloadMore Options
 About
 Press
 Blog
 People
 Papers
 Topics
 Biology Academy
 Engineering Academy
 Medicine Academy
 Job Board
 We're Hiring!
 Help Center

 Terms
 Privacy
 Copyright
 Academy ©2023

You might also like