Quiz - 5

Translate the previous program (with the declaration in the right place) to Python using the following code block.

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.

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

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

In the quiet rural village of Ponteironuloville, all phones have 6 digits. The telephone company establishes the following rules about numbers: | br |

  1. There cannot be two identical consecutive digits, because this is boring

  2. The sum of the digits must be even, because this is legal

  3. 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.

You have attempted of activities on this page