OOP + Python3 Basics coding exercises

¡Supera tus tareas y exámenes ahora con Quizwiz!

Sum of all squares of numbers Create a function called the sum_squares that returns the sum of all the squares of numbers between 0 and x(not included). Remember that you can use the range(x) function to generate a sequence of numbers from 0 to x (not included)

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_10.py

Factorial of a number A Create a function called factorial that would return the right factorial number Example: 4! = 1*2*3*4 = 24 Test cases: 4! should return 24 Test cases: 5! should return 120

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_11.py

Factorial of a number B Create a funtion named factorial that would return the factorial of n. Print the first 10 factorials (0 to 9) with the corresponding number. Note factorial of 0! is 1 Expected output 0! 1 1! 1 2! 2 3! 6 4! 24 5! 120 6! 720 7! 5040 8! 40320 9! 362880

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_12.py

sum in recursive way Create a function named sum_positive_numbers that take n as a number and apply recursive that would add the sum of the numnbers.

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_13.py

factorial recursive way Create a function named factorrial that would return the factorial of n using recursive.

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_14.py

Multiplication table with for loops Create a function that prints out a multiplication table(where each number is the result of multiplying the first number of its row by the number at the top of its column). Run the function so that it would print out the multiplication table of 1 to 3: 1 2 3 2 4 6 3 6 9

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_15.py

Counting numbers up or down create a counter function that counts down from start to stop when start is bigger than stop, count up from start to stop then.

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_16.py

return even numbers seperated by space Create a function named even_numbers that returns a space-seperated string all of positive numbers that are divisible by 2, up to and including the maximum that's passed into the function. For exampple, even_numbers(6) returns "2 4 6"

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_17.py

Palindrome The is_palindrome function checks if a string is a palindrome. A palindrome is a string that can be equally read from left to right or right to left, omitting blank spaces, and ignoring capitalization. Example of palindromes are words like kayak and radar, and phrases like "Never Odd Even". Create a function called is_palindrome to return True if the passed string is a palindrome, False is not.

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_19.py

Converting miles to kilometers Create a function called convert_distance_function that would returns the convertion from miles to kilometer and display the phrase "X miles equals Y km", with Y only 1 decimal place. For example, convert_distance(12) should return "12 miles equals 19.2 km"

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_20.py

nameTag Create a function named nametag that uses the format method to return first_name and the first initial of last_name followed by a period. For example, nametag("Jane", "Smith") should return "Jane S."

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_21.py

Skip next elment Create a function called skip_elements that would return a list containing every other element from an input list, starting with the first element. Tip: You can use for loop to iterate through the inut list

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_22.py

List Comprehensions A. Create a for loop that would loop from 1 to 10 and print the multiple of 7 (use list comprehension only) B. Create a list of programming language use list comprehension to loop over the list and print the length of each language C. Create a for loop using list comprehension that would print a list of numbers divisible by 3 (include 0)

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_23.py

Use of list comprehension Create a function called odd_numbers that would return a list of odd numbers between 1 and n, inclusively

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_24.py

Group list with join function Create a function called group_list that accepts a group name and a list of members, and returns a string with the format: group_name: member1, member2,...

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_25.py

Guess lists Create a function called guest_list that reads in a list of tuples with the name, age, and profession of each party guest, and prints the sentence "Guess is X years old and works as Y" for each one. For example, guest_list('Ken', 30, "Chef") should print out: Ken is 30 years old and works at as Chef

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_26.py

Counting how many times the letter appear in a word or sentence Create a function that would count the number of letter appears in a word or sentence Example: tenant t: 2 e: 1 n: 2 a: 1

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_27.py

access specifiers Create a function called groups_per_user that receives a dictionary, which contains group names with the list of users. input: { "local": ["admin", "userA"], "public": ["admin", "userB"], "administrator": ["admin"] } output: { 'admin': ['local', 'public', 'administrator'], 'userA': ['local'], 'userB': ['public'] }

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_28.py

Add total groceries values Create a function named add_prices that returns the total price of all of the groceries in the dictionary.

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_29.py

Squared of numbers with list comprehension Create a function and use list comprehension to create a list of squared numbers(n*n). The function receives the variables start and end, and returns a list of squres of consecutive numbers between start and end inclusively. For example, squares(2,3) should return [4, 9]

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_30.py

Car model and price with dictionary Create a function that would iterate through the keys and values of the car_prices dictionary, printing out some information about each one.

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_31.py

Counting letters Create a function named count_letters and use a dictionary to count the frequency of letter in the input string. Only letter should be counted, not blank spaces, numbers, or punctuation. Upper case should be considered the same as lower case. For example, count_letters("This is a sentence.") should return {'t': 2, 'h': 1, 'i': 2, 's': 3, 'a': 1, 'e': 3, 'n': 2, 'c': 1}.

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_32.py

Sort the array in decending order witouth moving the -1 in original index position You given an array [-1, 3, 5, -1, 55, 23, -1, 43]. Create a function that will sort this function in descending order without removing the -1 in their index position Expected ouput: [-1, 55, 43, -1, 23, 5, -1, 3]

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_6.py

HARD Demonstrate the 4 pillars of OOP: 1. Demonstrate the use of Classes & Objects 2. Demonstrate the use of Encapsulation & Abstractions 3. Demonstrate the use of Inheritance 4. Demonstrate the use of Polymorphism

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_1.py

String comparison [0] == [-1] Create a function called first_and_last that returns True if the first of the string is the same as the last letter of the string. False if they're different. Be careful how you handle the empty string, which should return True since nothing is equal to nothing.

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_18.py

Counting Frequncies in a list In this program, we have an array of elements to count the occurrence of its each element. One of the approaches to resolve this problem is to maintain one array to store the counts of each element of the array. Loop through the array and count the occurrence of each element as frequency and store it in another array Input : [1, 1, 1, 5, 5, 3, 1, 3, 3, 1, 4, 4, 4, 2, 2, 2, 2] Output : 1 : 5 2 : 4 3 : 3 4 : 3 5 : 2

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_7.py

Sum of all divisors Create a function that returns the sum of all of the divisors of a number, without including it. A divisor is a number that divides into another without remainder 0 # 0 total = 0 3 # shold sum of 1 total = 1 36 # shold sum of 1+2+3+4+6+12+18 total = 55 102 # should sum of 2+3+6+17+34+51 total = 114

Solution: https://github.com/felixandrewsapalaran/Python-Exercises/blob/master/solution_9.py


Conjuntos de estudio relacionados

Human resource management chapter for homework

View Set

MARK Chp 12 video assignment questions

View Set

Night (Section 5 & 6) test 3/13/18

View Set

Chemistry/Physics: Chemical Kinetics (Rate Laws) and Equilibrium

View Set