-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex_readme.py
43 lines (42 loc) · 2.94 KB
/
ex_readme.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Test your basic knowledge:
# 1. Define an integer, a float, a string.
# 2. Assign 5 values in one line.
# 3. Create 4 lists with: only numbers, only strings, only lists and all mixed together.
# 4. Add, delete, iterate, remove, change, access value in the list.
# 5. Play around with `* - + / % **` on the variables - what is possible for which variable type?
# 6. Create two lists called containing 10 instances of different variables. You are also required to create a list called big_list, which contains each variable, 10 times each, by concatenating the two lists you have created.
# 7. Write a format string with `%s, %f, %d`.
# 8. Test out `index(), count(), [start:stop:step], reverse, startswith(), endswith(), split(), lower(), upper()` functionalities of string.
# 9. Play around with `is not in and or`.
# 10. Create 4 functions with 4 different parameter types: default, keyword, variable numbers and required.
# 11. Create a list with a list inside - does it become one big list or a list with a second list in it?
# 12. Play with exceptions, implement 10 most popular mistakes in python made by the beginners and try/except them all with proper handling.
# 13. Create a class called `Programmer` with attributes `language` and `has_glasses` that inherits from a class called `Person` with `age` and `name` attributes. Implement `__get_item__` and constructor for them.
# 14. Convert the list of weights to numpy array, then all of the weights from kg to lbs. Use the scalar conversion of 2.2 lbs per kg for conversion and print the result array in lbs. `weight_kg = [81.65, 97.52, 95.25, 92.98, 86.18, 88.45]`.
# 15. Fix the code to print out the correct information by changing the string:
# s = "Hey there! what should this string be?"
# # Length should be 20
# print("Length of s = %d" % len(s))
# # First occurrence of "a" should be at index 8
# print("The first occurrence of the letter a = %d" % s.index("a"))
# # Number of a's should be 2
# print("a occurs %d times" % s.count("a"))
# # Slicing the string into bits
# print("The first five characters are '%s'" % s[:5]) # Start to 5
# print("The next five characters are '%s'" % s[5:10]) # 5 to 10
# print("The thirteenth character is '%s'" % s[12]) # Just number 12
# print("The characters with odd index are '%s'" %s[1::2]) #(0-based indexing)
# print("The last five characters are '%s'" % s[-5:]) # 5th-from-last to end
# # Convert everything to uppercase
# print("String in uppercase: %s" % s.upper())
# # Convert everything to lowercase
# print("String in lowercase: %s" % s.lower())
# # Check how a string starts
# if s.startswith("Str"):
# print("String starts with 'Str'. Good!")
# # Check how a string ends
# if s.endswith("ome!"):
# print("String ends with 'ome!'. Good!")
# # Split the string into three separate strings,
# # each containing only a word
# print("Split the words of the string: %s" % s.split(" "))