Python-Codelab

1. Assume there are two variables , k and m, each already associated with a positive integer valueand further assume that k’s value is smaller than m’s. Write the code necessary to compute thenumber of perfect squares between k and m. (A perfect square is an integer like 9, 16, 25, 36 thatis equal to the square of another integer (in this case 3*3, 4*4, 5*5, 6*6 respectively).)Associate the number you compute with the variable q. For example, if kand m had the values 10 and40 respectively, you would assign 3 to q because between 10 and 40 there are these perfect squares:16, 25, and 36,.2. Assume the availability of a function is_prime. Assume a variable n has been associated withpositive integer. Write the statements needed to compute the sum of the first n prime numbers. Thesum should be associated with the variable total. Note: is_prime takes an integer as a parameter and returns True if and only if that integer isprime. 3. Assume the availability of a function is_prime. Assume a variable n has been associated withpositive integer. Write the statements needed to find out how many prime numbers (starting with 2and going in increasing order with successively higher primes [2,3,5,7,11,13,…]) can be addedbefore exceeding n. Associate this number with the variable k. 4. Write the definition of a function named sum_list that has one parameter, a list whose elementsare of type int. The function returns the sum of the elements of the list as an int. 5. Define a function is_prime that receives an integer argument and returns true if the argument isa prime number and otherwise returns false. (An integer is prime if it is greater than 1 and cannotbe divided evenly [with no remainder] other than by itself and one. For example, 15 is not primebecause it can be divided by 3 or 5 with no remainder. 13 is prime because only 1 and 13 divide itwith no remainder.) This function may be written with a for loop, a while loop or using recursion. 6. Given the strings s1and s2, not necessarily of the same length, create a new string consistingof alternating characters of s1and s2 (that is, the first character of s1 followed by the firstcharacter of s2, followed by the second character of s1, followed by the second character of s2,and so on. Once the end of either string is reached, no additional characters are added. Forexample, if s1 contained “abc” and s2 contained “uvwxyz”, then the new string should contain“aubvcw”. Assign the new string to the variable s3. 7. Given the strings s1 and s2, not necessarily of the same length, create a new string consistingof alternating characters of s1 and s2 (that is, the first character of s1 followed by the firstcharacter of s2, followed by the second character of s1, followed by the second character of s2,and so on. Once the end of either string is reached, the remainder of the longer string is added tothe end of the new string. For example, if s1 contained “abc” and s2contained “uvwxyz”, then thenew string should contain “aubvcwxyz”. Associate the new string with the variable s3. 8. Given a variable s that is associated with the empty string, write some statements that use awhile loop to associate s with a string consisting of exactly 777 asterisks (*) .9. Given a variable n that is associated with a positive integer and a variable s that isassociated with the empty string, write some statements that use a while loop to associate s with astring consisting of exactly n asterisks (*) . (So if n were associated with 6 then s would, in theend, be associated with “******” .10. Given a variable s that is associated with non-empty string, write some statements that use awhile loop to associate a variable vowel_count with the number of lower-case vowels(“a”,”e”,”i”,”o”,”u”) in the string . 11. Given a variable n that is associated with a positive integer and a variable s that isassociated with the empty string, write some statements that use a while loop to associate s with astring consisting of exactly 2n asterisks (*) . (So if n were associated with 4 then s would, inthe end, be associated with “********” . 12. Given a variable t that is associated with a tuple whose elements are numbers, write somestatements that use a while loop to count the number of times the first element of the tupleappears in the rest of the tuple, and associate that number with the variable repeats. Thus if thetuple contains(1,6,5,7,1,3,4,1), then repeats would be assigned the value 2 because after the first“1” there are two more “1”s.