Examen Programación Python
Examen Programación Python
NAME
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.
===TEMPLATE TO DELIVER===
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 = '$'
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']
BLO 5
import matplotlib.pyplot as plt
Deliver individually in ATENEA before next class ONLY the auto-evaluation table.