From 51caca8b9210cba42f5b3d9088ab42d02d7bbabb Mon Sep 17 00:00:00 2001 From: Arie Bregman Date: Sat, 9 Apr 2022 23:22:06 +0300 Subject: [PATCH] Devel (#216) * Add a couple of exercises Also fixed the link for kubernetes exercises. * Fix kubernetes images Also fixed the link to containers exercises. * Move Python exercises to a separate repository This is the first part in moving Python exercises into their own repository. --- README.md | 301 +----------------------------------------------------- 1 file changed, 1 insertion(+), 300 deletions(-) diff --git a/README.md b/README.md index 26d75c9..e8c488b 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ programming
Software Development
- Python
Python
+ Python
Python
go
Go
Bash
Shell Scripting
kubernetes
Kubernetes
@@ -2840,263 +2840,6 @@ Yes, it's a operating-system-level virtualization, where the kernel is shared an The introduction of virtual machines allowed companies to deploy multiple business applications on the same hardware while each application is separated from each other in secured way, where each is running on its own separate operating system. -## Python - -### Python Exercises - -|Name|Topic|Objective & Instructions|Solution|Comments| -|--------|--------|------|----|----| -| Identify the data type | Data Types | [Exercise](exercises/python/data_types.md) | [Solution](exercises/python/solutions/data_types_solution.md) -| Identify the data type - Advanced | Data Types | [Exercise](exercises/python/advanced_data_types.md) | [Solution](exercises/python/solutions/advanced_data_types_solution.md) -| Reverse String | Strings | [Exercise](exercises/python/reverse_string.md) | [Solution](exercises/python/solutions/reverse_string.md) -| Compress String | Strings | [Exercise](exercises/python/compress_string.md) | [Solution](exercises/python/solutions/compress_string.md) - -### Python Self Assessment - -
-What are some characteristics of the Python programming language?
- -``` -1. It is a high level general purpose programming language created in 1991 by Guido Van Rosum. -2. The language is interpreted, being the CPython (Written in C) the most used/maintained implementation. -3. It is strongly typed. The typing discipline is duck typing and gradual. -4. Python focuses on readability and makes use of whitespaces/identation instead of brackets { } -5. The python package manager is called PIP "pip installs packages", having more than 200.000 available packages. -6. Python comes with pip installed and a big standard library that offers the programmer many precooked solutions. -7. In python **Everything** is an object. -``` -
- -
-What built-in types Python has?
- - List - Dictionary - Set - Numbers (int, float, ...) - String - Bool - Tuple - Frozenset -
- -
-What is mutability? Which of the built-in types in Python are mutable?
- -Mutability determines whether you can modify an object of specific type. - -The mutable data types are: - - List - Dictionary - Set - -The immutable data types are: - - Numbers (int, float, ...) - String - Bool - Tuple - Frozenset -
- -#### Python - Booleans - -
-What is the result of each of the following? - - - 1 > 2 - - 'b' > 'a' - * 1 == 'one' - - 2 > 'one'
- - * False - * True - * False - * TypeError -
- -
-What is the result of `bool("")`? What about `bool(" ")`? Explain
- -bool("") -> evaluates to False
-bool(" ") -> evaluates to True -
- -
-What is the result of running [] is not []? explain the result
- -It evaluates to True.
-The reason is that the two created empty list are different objects. `x is y` only evaluates to true when x and y are the same object. -
- -
-What is the result of running True-True?
- -0 -
- -#### Python - Strings - -
-True or False? String is an immutable data type in Python
- -True -
- -
-How to check if a string starts with a letter?
- -Regex: - -``` -import re -if re.match("^[a-zA-Z]+.*", string): -``` - -string built-in: - -``` -if string and string[0].isalpha(): -``` -
- -
-How to check if all characters in a given string are digits?
- -`string.isdigit` -
- -
-How to remove trailing slash ('/') from a string?
- -`string.rstrip('/')` -
- -
-What is the result of of each of the following? - - - "abc"*3 - - "abc"*2.5 - - "abc"*2.0 - - "abc"*True - - "abc"*False
- -* abcabcabc -* TypeError -* TypeError -* "abc" -* "" -
- -
-Improve the following code: - -``` -char = input("Insert a character: ") -if char == "a" or char == "o" or char == "e" or char =="u" or char == "i": - print("It's a vowel!") -``` -
- -``` -char = input("Insert a character: ") # For readablity -if lower(char[0]) in "aieou": # Takes care of multiple characters and separate cases - print("It's a vowel!") -``` -OR -``` -if lower(input("Insert a character: ")[0]) in "aieou": # Takes care of multiple characters and small/Capital cases - print("It's a vowel!") -``` -
- -#### Python - Functions - -
-How to define a function with Python?
-Using the `def` keyword. For Examples: - -``` -def sum(a, b): - return (a + b) -``` -
- -
-In Python, functions are first-class objects. What does it mean?
- -In general, first class objects in programming languages are objects which can be assigned to variable, used as a return value and can be used as arguments or parameters.
-In python you can treat functions this way. Let's say we have the following function - -``` -def my_function(): - return 5 -``` - -You can then assign a function to a variables like this `x = my_function` or you can return functions as return values like this `return my_function` -
- -#### Python - Integer - -
-Write a function to determine if a number is a Palindrome
- -- Code: - -``` -from typing import Union - -def isNumberPalindrome(number: Union[int, str]) -> bool: - if isinstance(number, int): - number = str(number) - return number == number[::-1] - -print(isNumberPalindrome("12321")) -``` - -- Using Python3.10 that accepts using bitwise operator '|'. - -``` -def isNumberPalindrome(number: int | str) -> bool: - if isinstance(number, int): - number = str(number) - return number == number[::-1] - -print(isNumberPalindrome("12321")) -``` - -Note: Using slicing to reverse a list could be slower than other options like `reversed` that return an iterator. - -- Result: - -``` -True -``` - -
- -#### Python - Loops - -
-What is the result of the following block of code? - -``` -x = ['a', 'b', 'c'] -for i in x: - if i == 'b': - x = ['z', 'y'] - print(i) -``` -
- -``` -a -b -c -``` -
- #### Python - OOP
@@ -3457,12 +3200,6 @@ List, as opposed to a tuple, is a mutable data type. It means we can modify it a `x.append(2)`
-
-How to check how many items a list contains?
- -`len(sone_list)` -
-
How to get the last element of a list?
@@ -3483,30 +3220,6 @@ Don't use `append` unless you would like the list as one item. `my_list[0:3] = []`
-
-How do you get the maximum and minimum values from a list?
- -``` -Maximum: max(some_list) -Minimum: min(some_list) -``` -
- -
-How to get the top/biggest 3 items from a list?
- -``` -sorted(some_list, reverse=True)[:3] -``` - -Or - -``` -some_list.sort(reverse=True) -some_list[:3] -``` -
-
How to insert an item to the beginning of a list? What about two items?
@@ -3860,14 +3573,6 @@ with open('file.txt', 'w') as file: ```
-
-How to print the 12th line of a file?
-
- -
-How to reverse a file?
-
-
Sum all the integers in a given file
@@ -3965,10 +3670,6 @@ with open('file.json', 'w') as f: Using the re module -
-How to substitute the string "green" with "blue"?
-
-
How to find all the IP addresses in a variable? How to find them in a file?