Skip to content

Instantly share code, notes, and snippets.

@MacHu-GWU
Created January 26, 2017 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MacHu-GWU/c0e9b96d1ca9ce7e5913cb4bb2ed1aef to your computer and use it in GitHub Desktop.
Save MacHu-GWU/c0e9b96d1ca9ce7e5913cb4bb2ed1aef to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
2017-01-26
You have to under stand these:
basic concept:
- variable
- function
- method
- type
- instance
and answer these questions:
1. both function and method can take some input argument and give an output,
what's the difference between function and method?
2. what's the relationship between type and instance? give me an example
of ``string type`` and ``string instance``.
under stand basic data type:
- int: integer
- float: float
- str: string
- * list:
- set:
- * dict: dictionary
and answer these questions:
- list, set, dict, they are all data collection type, what's the differente?
- MVA have a number generator system, which container we should use to store
sequence of line number. e.g. D32, C102, ...
- Each student have an unique student id, we have two class, A and B.
If we need to find out how many student sign up both, which container we should use?
- Each student have an unique student id (GWU-0001, GWU-0002, ...) and it's name.
The library need a student information look up system, by providing student id, which container we should use?
Then you should get familiar with method of (IF YOU FEEL BORED, read the homework
and then go back here):
- str.split
- str.replace
- str.index
- str.find
- and also: https://docs.python.org/3.5/library/stdtypes.html?highlight=str#string-methods
- list.append
- and also: https://docs.python.org/3.5/tutorial/datastructures.html?highlight=list%20append#more-on-lists
- set.union
- set.instersection
- set.difference
- and also: https://docs.python.org/3.5/library/stdtypes.html?highlight=set%20type#set
- dict.get
- and also: https://docs.python.org/3.5/library/stdtypes.html?highlight=dictionary#mapping-types-dict
"""
#--- Homework One ---
# trump's secatary want's to leak some message to newspaper by sending them
# email, but he wants to encrypt it. This ``encrypted_text`` is what the editor got.
# ``dictionary`` is the dictionary to encrypt it. please complete the
# decrypt_it(encrypted_text, dictionary) function to solve the original_text
#
# Copy the entire script to: https://repl.it/languages/python3, and try.
encrypted_text = \
"""
Smkncwkfs Kxfubw Jmyvl tun wkrcwkw tk qcbb nkke sx lup jxm stk qubb xf stk DB'n nxystkmf gxmwkm gp cvlxncfa u 20% suz xf cvlxmsn jmxv Ckzcrx ufw un lums xj u bumakm rxvlmktkfncok suz mkjxmv lbuf, stk Utcsk Fxynk nucw Jtymnwup.
Utcsk Fxynk lmknn nkrmksump Bkuf Blcrkm nucw stk rxvlmktkfncok suz mkjxmv lureuak Jmyvl ufw Wklygbcrufn umk bxxecfa sx lys sxakstkm qcbb cfrbywk suzcfa cvlxmsn jmxv xstkm rxyfsmckn, bcek Ckzcrx.
"Lp wxcfa cs stus qk ruf wx $10 gcbbcxf u pkum ufw kuncbp lup jxm stk qubb iyns stmxyat stus vkrtufcnv ubxfk. Jtus'n mkubbp axcfa sx lmxocwk stk jyfwcfa," Blcrkm nucw, mkjkmmcfa sx u 20% suz. Irrxmwcfa sx stk Ojjcrk xj stk DB Jmuwk Wklmknkfsuscok, Ckzcrx'n kzlxmsn sx stk DB cf 2015 qun oubykw us $316.4 gcbbcxf. Jtk smuwk wkjcrcs cn knscvuskw sx gk $50 gcbbcxf.
Jtk fkq Utcsk Fxynk lbuf rxvkn un stk Ckzcruf Smkncwkfs rufrkbkw u lbuffkw vkkscfa qcst Jmyvl ujskm stk DB lmkncwkfs ncafkw uf kzkryscok xmwkm Ukwfknwup ecrecfa xjj stk lmxrknn xj gycbwcfa stk gxmwkm qubb ufw oxqkw xfrk uaucf sx jxmrk Ckzcrx sx lup jxm cs.
"""
dictionary = {
'c': 'r', 'b': 'g', 'a': 'u', 'g': 'a', 'f': 'j', 'e': 'k', 'd': 'w',
'k': 'e', 'j': 'i', 'i': 'c', 'h': 't', 'o': 'x', 'n': 'f', 'm': 'v',
'l': 'b', 's': 'n', 'r': 'm', 'q': 'd', 'p': 'l', 'w': 'q', 'v': 'o',
'u': 'y', 't': 's', 'z': 'h', 'y': 'p', 'x': 'z', 'C': 'M', 'B': 'L',
'A': 'I', 'G': 'P', 'F': 'X', 'E': 'R', 'D': 'K', 'K': 'A', 'J': 'V',
'I': 'N', 'H': 'F', 'O': 'O', 'N': 'E', 'M': 'C', 'L': 'Q', 'S': 'B',
'R': 'W', 'Q': 'Y', 'P': 'S', 'W': 'U', 'V': 'Z', 'U': 'D', 'T': 'J',
'Z': 'H', 'Y': 'G', 'X': 'T',
}
def decrypt_it(encrypted_text, dictionary):
"""write a function take the encrypted_text and the dictionary as input,
solve the original_text and return.
"""
# Don't edit anything above here!!!
# Put your code here!
original_text = None # Assign your solve to this variable
return original_text
# Don't edit anything below here!!!
original_text = decrypt_it(encrypted_text, dictionary)
try:
flag = True
for word in ["comprehensive", "Republicans", "executive"]:
if word not in original_text:
print("Opps, wrong answer!")
flag = False
if flag:
print("Congratulation! Original text is:")
print(original_text)
except:
print("Opps, wrong answer!")
#--- Below is for teach Hu ---
original_text = \
"""
President Donald Trump has decided he will seek to pay for the wall on the US's southern border by imposing a 20% tax on imports from Mexico and as part of a larger comprehensive tax reform plan, the White House said Thursday.
White House press secretary Sean Spicer said the comprehensive tax reform package Trump and Republicans are looking to put together will include taxing imports from other countries, like Mexico.
"By doing it that we can do $10 billion a year and easily pay for the wall just through that mechanism alone. That's really going to provide the funding," Spicer said, referring to a 20% tax. According to the Office of the US Trade Representative, Mexico's exports to the US in 2015 was valued at $316.4 billion. The trade deficit is estimated to be $50 billion.
The new White House plan comes as the Mexican President canceled a planned meeting with Trump after the US president signed an executive order Wednesday kicking off the process of building the border wall and vowed once again to force Mexico to pay for it.
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment