0% found this document useful (0 votes)
16 views4 pages

Examen Programación Python

The document provides exercises (BLO1-BLO5) for a programming exam. It includes the problems, empty templates to fill out for self-evaluation, and the solutions. The exercises involve currency conversion, digit summation, filtering numbers, extracting the first word from a string, and plotting planting months for vegetables from an array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Examen Programación Python

The document provides exercises (BLO1-BLO5) for a programming exam. It includes the problems, empty templates to fill out for self-evaluation, and the solutions. The exercises involve currency conversion, digit summation, filtering numbers, extracting the first word from a string, and plotting planting months for vegetables from an array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

D8 individual Preparation for BLOs1-5 Home Atenea

NAME

Do this exam, first in paper with a limit of time of 1h30’.


Then check the results given compared with your solutions and deliver the summary
table filled.

Basic Learning Objectives


BLO 1
Write a program that implements a CurrencyConverter (from euros to dollars and vice versa). The
program will read from the console a number and then a character. The number will hold the
quantity of money and the letter ('$' or 'E') will indicate the currency (Dollars or Euros). The
program must display the result of the conversion. Assume that 1 Euro is equal to 1.4 Dollars.

BLO 2
Write a program that reads from the keyboard a number and calculates the summation of the digits
in odd positions. Assume that digit positions start from right to left. For instance, for the number
49263 the digit in position 1 is digit 3, and the summation of the digits in odd positions is 3+2+4=9.

BLO 3
Write a program that reads a sequence of numbers from keyboard, finished with 0, and shows the
two first numbers that are multiple of 2 and greater 21. For example, entering the sequence 23, 48,
5, -6, 41, 990, ... the program will show the numbers 48 and 990 and will stop immediately after
showing 990.

BLO 4
Define a vector of characters f that contains a sentence finished with character '.' such as
f = list(“Esto es una frase de prueba.”) and write a program that shows the first word of f that
starts with a lower case vocal. In the example it will show “es”.
Note1: words are separated by space characters ' '.
Note2: lower case vocal letters are 'a', 'e', 'i', 'o', and 'u'. Do not consider accents!

BLO5*
We have an array veg which contains the months in which a list of vegetables can be plant. Each
row has the information of a vegetable and columns (2) contains the first and last month in which
that vegetable can be planted. Write a program that ask the user for a vegetable row number and its
name and shows a plot of the months when this vegetables can be planted.

(continues in next page)


EXAMPLE: The plot should look like the image bellow if veg = [[2,5], [4,6], [1,7], [8,8], [4,5],
[1,12], [10,11]]; and the user inputs: the row 5 and provides the vegetable name 'cabbage'.

===TEMPLATE TO DELIVER===

Look at the official solutions and contrast them with yours.


Fill up the following template table and deliver it in ATENEA before the next class.

Correct* Clear*
Exercice Justification
(G/F/P) (G/F/P)

BLO1

BLO2

BLO3

BLO4

BLO5
*Correct:
Good: The code is nearly identical to the solution. Small differences with the solution, but I can justify it well.
Fair: The code is similar to the solution. There are one or two errors in the code that can be fixed easyly.
Poor: There are many errors. To fix my solution I would have to start from the beginning.
*Clear:
Good: The code is well indented. The comments help to understand well the code.
Fair: A small part of the code is not properly indented, and some comments are not sufficiently clear.
Poor: The code is not well indented, and there are not comment (or they are not clear enough).

Deliver individually in ATENEA before the next class. Deliver ONLY the above table.
SOLUTIONS
BLO 1
DOLLARS_PER_EURO = 1.4
EURO = 'E'
DOLLAR = '$'

money = float(input("Enter the quantity of money: "))


currency = input(f"Enter the currency ({EURO}: Euros, {DOLLAR}: Dollars): ")

if currency == EURO:
result = money * DOLLARS_PER_EURO
print(result, DOLLAR)
elif currency == DOLLAR:
result = money / DOLLARS_PER_EURO
print(result, EURO)
else:
print(f"Currency '{currency}' not available")

BLO 2
number = int(input("N: "))
odd_digits_sum = 0
while number > 0:
number, digit = divmod(number, 10)
odd_digits_sum += digit
number //= 10
print(odd_digits_sum)

BLO 3
DIVISOR = 2
LOWER_BOUND = 21
REQUIRED_COUNT = 2
TERMINATOR = 0

found_numbers_count = 0
is_sequence_ended = False
while found_numbers_count < REQUIRED_COUNT and not is_sequence_ended:
number = int(input(f"Enter a number ({TERMINATOR} to finish): "))
if number == TERMINATOR:
is_sequence_ended = True
elif number > LOWER_BOUND and number % DIVISOR == 0:
found_numbers_count += 1
print(number)
BLO 4
VOCALS = ['a', 'e', 'i', 'o', 'u']

f = list("Esto es una frase de prueba.")


encontrado = False
n=0
while f[n] != '.' and not encontrado:
# test if we are at the begining of a word
if n == 1 or n > 1 and f[n - 1] == ' ':
# test if the initial letter is a vocal
i=0
while i < len(VOCALS) and not encontrado:
if f[n] == VOCALS[i]:
encontrado = True
i += 1
if not encontrado:
n += 1
if encontrado:
# show all letters of the current word
while f[n] != ' ' and f[n] != '.':
print(f[n], end='')
n += 1
else:
print("There is no word starting with vocal")

BLO 5
import matplotlib.pyplot as plt

MONTHS = range(1, 13) # 1, 2, ..., 12


MONTHS_COUNT = len(MONTHS)

veg = [[2,5], [4,6], [1,7], [8,8], [4,5], [1,12], [10,11]]


row_number = int(input("Enter vegetable -number of row from1 to LEN- : ")) -1
name = input("Enter vegetable -name- : ")
counters = [0] * MONTHS_COUNT
month = veg[row_number][0]
while month <= veg[row_number][1]:
counters[month - 1] = 1
month += 1
plt.bar(MONTHS, counters)
plt.title(name)
plt.show()

Deliver individually in ATENEA before next class ONLY the auto-evaluation table.

You might also like