Quiz - 5¶
x = 2 if y > 8 then: y = 5 y = y * 2 else: x = x * 2 print(x + y):
Translate the previous program (with the declaration in the right place) to Python using the following code block.
Q-3: What does the previous program print?
for i = 1 to 9:
if i != 3 then:
for j = 1 to 6:
print("Hello")
Translate the previous program to Python using the following code block.
Note: in our pseudolanguage, the loop includes the endpoints, that is, 1 to 4 means 1, 2, 3, 4.
Q-5: How many times does the previous program print "Hello"
?
Develop the function pares_divisibles_7
which receives two positive integers, inicio
and fin
, that represent the start and end of a range of numbers. The function must return the amount of numbers that are even and also divisible by 7.
Examples:
pares_divisibles_7(1, 7)
-> 0
pares_divisibles_7(25, 123)
-> 7
pares_divisibles_7(13, 245)
-> 17
Q-7: Use the function created in the previous exercise to answer How many numbers are even and also divisible by 7 between 1067 and 3627 (inclusive)?
Daniela is a very superstitious person. For her, a number is lucky if it contains the digit 2
but not the 7
. She is also very curious and wants to know how many lucky numbers are in a range of numbers (including the ends)?. That’s why she has asked you to make the function called cuantos_tienen_suerte
which receives two positive integers, inicio
and fin
, that represent the start and end of a range of numbers. The function must return the amount of numbers that are lucky.
Examples:
cuantos_tienen_suerte(1, 7)
-> 1
cuantos_tienen_suerte(1, 20)
-> 3
cuantos_tienen_suerte(25, 123)
-> 16
cuantos_tienen_suerte(13, 245)
-> 74
Q-9: Use the function created in the previous exercise (MANDATORY to have finished it before and passed all tests) to answer How many lucky numbers are there between 18644 and 33087 (inclusive)?
In the quiet rural village of Ponteironuloville, all phones have 6 digits. The telephone company establishes the following rules about numbers: | br |
There cannot be two identical consecutive digits, because this is boring
The sum of the digits must be even, because this is legal
The last digit cannot be the same as the first, because that is bad luck.
Then, given these perfectly reasonable, well-designed and mature rules, develop the function called es_numero_ponteironuloville
that receives a string of positive integers and returns True
if the number is valid according to the rules of Ponteironuloville and False
otherwise.
| br | | br |
Examples: | br |
es_numero_ponteironuloville("123457")
-> True
| br |
es_numero_ponteironuloville("234562")
-> False
| br |
es_numero_ponteironuloville("222222")
-> False
| br |
es_numero_ponteironuloville("123456")
-> False
| br |
es_numero_ponteironuloville("312214")
-> False
| br |
es_numero_ponteironuloville("312312")
-> True
| br |
Knowing that the split()
function divides a string into multiple strings, use the function created in the previous exercise (MANDATORY to have finished it before and passed all tests) to complete the count_valid
function that returns the number of valid numbers from the list of numbers given in the following block of code.
Note: the list of numbers is a string, wisely use the split()
function to obtain a list of strings.
Q-12: Use the function created in the previous exercise to answer how many numbers from the list are valid according to the rules of Ponteironuloville?