Journey Recording for Coding

Echo H.
3 min readMay 26, 2019

--

  1. Python

Book in use: Python Crash Course

Day 3 Simplify

Day 4,

cars.insert(0,’ducati’), cars.append(‘ducati’), del cars[0], new_cars=cars.pop(0), print(“…” + new_cars.title())

Permanent organizing: cars.sort(), cars.sort(reverse=True), cars.reverse()

Temporary: print(sorted(cars))

Length: len(cars)

Day 5 Organizing a lists

lists.sort(reverse = True) — permanently sort in alphabetic order.

print(sorted(lists, reverse = True) — temporarily sorted.

popped_lists = lists.pop() — select the element from lists.

lists.append(‘element_new’) — add a new element in lists.

Day 7 If Conditional Statement — write code concisely and consistently.

if car ==’bmw’:

print (car.upper())

else:

print(car.title())

== — equal to?

Tuple immutable values in lists.

print(lists[0])

Day 8 If statement

if-elif-else:

Day 9 Loop, dictionaries (lists in lists, dictionaries in dictionaries)

when print number — str(number), when using number in dictionaries, do not use ‘6’, but simply use 6.

one dictionary — name = {‘echo’: ‘tokyo’},

dictionaries appending to a dictionary — names = [name,…]

I still have trouble in how to put more than 1 number in the dictionary by removing brackets but only showing the number: I used ‘echo’: [6, 8]

Reflection: an efficient way to eliminate repetitive typing, copying through writing a code, and then loop.

dictionaries

Day 10 Input() function, run Python on Terminal

Terminal: locate: cd Desktop/python_work/; ls rollercoaster.py; python rollercoaster.py; 5

This part gets interesting to write a program and being able to run and play, satisfied today after searching on youtube, running on treadmill to think how to run on terminal, and redoing the whole process again. I finally understood at this time.

input( )

Day 11 loop, while, dictionaries, remove (*need more practice, I am going to post my answers for practice problems and some reflections.)

for Python 2.7, using raw_input() for input(); additionally, you can work with idle and python shell through firstly using sublime text to save your file ending with .py, then opening up the file through python_work folder to work directly on these two programs. Sublime is unable to use input() function.
active for True or False, if True, While will keep looping. active = False, stop the loop; otherwise, the program will continue.
break is similar to False, which will tell the program to stop.
Exercise solution (1)
I tried to use range with the 2nd conditional statement, elif age ≤ 12:. age = int(age) should be put after input(). It is necessary to add int() for numbers.
Exercise (2) Telling the loop to stop at some point.
Exercise (3) remove() function needs to be attached with while statement.
Dictionary responses = {}, responses [name] = place to add items into dictionary. if == not if =. for name, place in responses.items()

Day 12 class, random(), import, def, parent and child class, seed(), uniform()

Useful resource founded (to get familiarized with more functions): https://pymotw.com/

Similar to Monte Carlo to work with random numbers

--

--