0% found this document useful (0 votes)
4 views

Ejercicios en clases funciones Python

The document outlines six programming tasks involving string manipulation, collection differences, summation of integers, counting squares, generating sequences, and checking character counts. Each task includes specific input-output examples to clarify the expected functionality. The tasks require implementing functions to perform operations on integers and strings, with considerations for edge cases.

Uploaded by

Miky A Sanjinez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Ejercicios en clases funciones Python

The document outlines six programming tasks involving string manipulation, collection differences, summation of integers, counting squares, generating sequences, and checking character counts. Each task includes specific input-output examples to clarify the expected functionality. The tasks require implementing functions to perform operations on integers and strings, with considerations for edge cases.

Uploaded by

Miky A Sanjinez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Implement

1. Create a function that takes 2 integers in form of a string as an input, and outputs the sum (also as
a string):

Example: (Input1, Input2 -→Output)

"4", "5" --> "9"


"34", "5" --> "39"
"", "" --> "0"
"2", "" --> "2"
"-5", "3" --> "-2"

Note: If either input is an empty string, consider it as zero.

2. Find the difference between two collections. The difference means that either the character is
present in one collection or it is present in other, but not in both. Return a sorted list with the
difference.

The collections can contain any character and can contain duplicates.

Example:

A = [a, a, t, e, f, i, j]

B = [t, g, g, i, k, f]

difference = [a, e, g, j, k]

3. Given two integers a and b, which can be positive or negative, find the sum of all the integers
between and including them and return it. If the two numbers are equal return a or b.

Note: a and b are not ordered!

Examples (a, b) --> output (explanation)

(1, 0) --> 1 (1 + 0 = 1)
(1, 2) --> 3 (1 + 2 = 3)
(0, 1) --> 1 (0 + 1 = 1)
(1, 1) --> 1 (1 since both are same)
(-1, 0) --> -1 (-1 + 0 = -1)
(-1, 2) --> 2 (-1 + 0 + 1 + 2 = 2)

Your function should only return a number, not the explanation about how you get that number.

4. Write a function get_number_of_squares(n) that will return how many integer (starting from 1,
2...) numbers raised to power of 2 and then summed up are less than some number given as a
parameter.

E.g 1: For n = 6 result should be 2 because 1^2 + 2^2 = 1 + 4 = 5 and 5 < 6


E.g 2: For n = 15 result should be 3 because 1^2 + 2^2 + 3^2 = 1 + 4 + 9 = 14 and 14 < 15
5. Guess the Sequence
You have read the title: you must guess a sequence. It will have something to do with the number
given.

Example:

x = 16

result = [1, 10, 11, 12, 13, 14, 15, 16, 2, 3, 4, 5, 6, 7, 8, 9]

6. Check to see if a string has the same amount of 'x's and 'o's. The method must return a boolean
and be case insensitive. The string can contain any char.

Examples input/output:

XO("ooxx") => true


XO("xooxx") => false
XO("ooxXm") => true
XO("zpzpzpp") => true // when no 'x' and 'o' is present should return true
XO("zzoo") => false

You might also like