Skip to content

28-Python exercises/tests - CodeWars - archive (TOTAL SOLUTIONS -- 87-Ruby, 40-JavaScript, 28-Python, 25-PHP) (RANK -- 90th percentile)

Notifications You must be signed in to change notification settings

Jiaziwang/python-codewars-archive

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

#Python CodeWars Review

Archive of completed CodeWars exercises, languages - Python

Short description and numbered in chronological order.

#Python

  • 1 Remove all whitespace from object (string)

  • 2 Multiply two integers and return the product

  • 3 Return (Even) or (Odd) depending on the integer value of (number)

  • 4 Simple, given a string of words, return the length of the shortest word(s). String will never be empty and you do not need to account for different data types.

  • 5 Sum all the numbers of the array (in F# and Haskell you get a list) except the highest and the lowest element
    (the value, not the index!). (The highest/lowest element is respectively only one element at each edge, even if there are more than one with the same value!)

  • 6 In this little assignment you are given a string of space separated numbers, and have to return the highest and lowest number.

  • 7 Write function avg which calculates average of numbers in given list.

  • 8 Return the given string (st) with the order of words reversed.

  • 9 Alex just got a new hula hoop, he loves it but feels discouraged because his little brother is better than him Write a program where Alex can input (n) how many times the hoop goes round and it will return him an encouraging message :) -If Alex gets 10 or more hoops, return the string "Great, now move on to tricks". -If he doesn't get 10 hoops, return the string "Keep at it until you get it".

  • 10 Given a random string consisting of numbers, letters, symbols, you need to sum up the numbers in the string. Note: Consecutive integers should be treated as a single number. eg, 2015 should be treated as a single number 2015, NOT
    four numbers All the numbers should be treaded as positive integer. eg, 11-14 should be treated as two numbers 11 and 14. Same
    as 3.14, should be treated as two numbers 3 and 14 If no number was given in the string, it should return 0

  • 11 Return boolean (true, false) confirming if (string) is an isogram (contains no duplicate characters).

  • 12 Simple correction of 'order of operations' function.

  • 13 Return true if string contains only digits, false otherwise or false if empty.

  • 14 Find length of shortest word in string. (Python sort is alphabetic. you have to define key=len)

  • 15 Your friend advised you to see a new performance in the most popular theater in the city. He knows a lot about art and his advice is usually good, but not this time: the performance turned out to be awfully dull. It's so bad you want to sneak out, which is quite simple, especially since the exit is located right behind your row to the left. All you need to do is climb over your seat and make your way to the exit.

The main problem is your shyness: you're afraid that you'll end up blocking the view (even if only for a couple of seconds) of all the people who sit behind you and in your column or the columns to your left. To gain some courage, you decide to calculate the number of such people and see if you can possibly make it to the exit without disturbing too many people.

Given the total number of rows and columns in the theater (nRows and nCols, respectively), and the row and column you're sitting in, return the number of people who sit strictly behind you and in your column or to the left, assuming all seats are occupied.

  • 16 Create a method is_uppercase() to see whether the string is ALL CAPS.

  • 17 Give a list, find the average of all the values.

  • 18 Write a function getMean that takes as parameters an array (arr) and 2 integers (x and y). The function should return the mean between the mean of the the first x elements of the array and the mean of the last y elements of the array.

The mean should be computed if both x and y have values higher than 1 but less or equal to the array's length. Otherwise the function should return -1.

  • 19 Consider an array of sheep where some sheep may be missing from their place. We need a function that counts the number of sheep present in the array (true means present).

  • 20 Timmy & Sarah think they are in love, but around where they live, they will only know once they pick a flower each. If one of the flowers has an even number of petals and the other has an odd number of petals it means they are in love.

Write a function that will take the number of petals of each flower and return true if they are in love and false if they aren't.

  • 21 Positive integers that are divisible exactly by the sum of their digits are called Harshad numbers, see Wikipedia for further details. Write a function numberJoy() which tests if a positive integer n is Harshad and returns True if the product of its digit sum, and its digit sum reversed, equals n. Otherwise return False.

  • 22 Complete the squareSum method so that it squares each number passed into it and then sums the results together.

  • 23 Given a list of integers, invert the values of all integers from negative to positive or positive to negative.

  • 24 "Identical Elements" Compare two lists and return boolean based on whether they contain any of the same values.

  • 25 "Volume of a Cuboid" Return the volume of a cube, given the dimensions.

  • 26 "Convert a Number to a String!" - super simple Return integer give a number value as string.

  • 27 "Plural" - We need a simple function that determines if a plural is needed or not. It should take a number, and return true if a plural should be used with that number or false if not. This would be useful when printing out a string such as 5 minutes, 14 apples, or 1 sun.

  • 28 "Circle area inside square" - Turn an area of a square in to an area of a circle that fits perfectly inside the square.

About

28-Python exercises/tests - CodeWars - archive (TOTAL SOLUTIONS -- 87-Ruby, 40-JavaScript, 28-Python, 25-PHP) (RANK -- 90th percentile)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%