Skip to content

Instantly share code, notes, and snippets.

@ChuckleQu
ChuckleQu / 01_Day_Introduction.py
Last active September 16, 2020 13:52
01_Day_Introduction
# Introduction
# Day 1 - 30DaysOfPython Challenge
print(2 + 3) # addition(+)
print(3 - 1) # subtraction(-)
print(2 * 3) # multiplication(*)
print(3 / 2) # division(/)
print(3 ** 2) # exponential(**)
print(3 % 2) # modulus(%)
print(3 // 2) # Floor division operator(//)
@ChuckleQu
ChuckleQu / 02_Day_Casting.py
Last active September 16, 2020 13:52
02_Day_Variables_builtin_functions
# Casting(转换):将一种数据类型转换为另一种数据类型
# int to float
num_int = 10
print('num_int:', num_int) # 10
num_float = float(num_int)
print('num_float:', num_float) # 10.0
# float to int
gravity = 9.81
# Arithmetic Operators in Python
# Integers
print('Division without remainder', 7 // 2) # Gives without floating number or without the remainder
print('Modulus', 3 % 2) # Gives the remainder
print('Exponentiation:', 3 ** 2) # it mean 3^2
print('Mutiplying complex numbers:', (1+1j) * (1-1j))
# The most common escape characters:
# \n: new line
# \t: Tab (means 8 spaces)
# \\: Back slash (反斜杠,slash:斜杠)
# \': Single quote (')
# \": Double quote (")
print('I hope everyone is enjoying the Python Challenge.\nAre you ?') # \n: line break(换行符)
print('Days\tTopics\tExercises')
@ChuckleQu
ChuckleQu / 05_Day_Exercise_Level_1.py
Last active September 16, 2020 13:59
05_Day_Lists
# 1
# method 1
lst = []
# method 2
lst = list()
# 2
lst = ['Beijing', 'Shanghai', 'Guangzhou', 'Shenzhen', 'Hangzhou']
# 3
@ChuckleQu
ChuckleQu / 06_Day_Exercise.py
Created September 16, 2020 14:01
06_Day_Tuple
# 1
# method 1
empty_tuple = ()
print(empty_tuple)
# method 2
empty_tuple = tuple()
print(empty_tuple)
# 2 & 3
sisters = ('Alice', 'Cici')
@ChuckleQu
ChuckleQu / 07_Day_Exercise.py
Created September 16, 2020 14:01
07_Day_Sets
# sets
it_companies = {'Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon'}
A = {19, 22, 24, 20, 25, 26}
B = {19, 22, 20, 25, 26, 24, 28, 27}
age = [22, 19, 24, 25, 26, 24, 25, 24]
# 1
print(len(it_companies))
# 2
@ChuckleQu
ChuckleQu / 08_Day_Dictionaries.py
Last active September 16, 2020 14:05
08_Day_Dictionaries
# A dictionary is a collection of unordered, modifiable(mutable) paired (key: value) data type.
# Creating a Dictionary
# To create a dictionary we use curly brackets, {}.
# syntax
empty_dict = {}
# Dictionary with data values
dct = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3', 'key4': 'value4'}
person = {
'first_name': 'Fangyu',
'last_name': 'Qu',
@ChuckleQu
ChuckleQu / 09_Day_Conditionals.py
Created September 16, 2020 14:07
09_Day_Conditionals
# If Condition
# In python and other programming languages,
# the key word if we use to check if a condition is true and to execute the block code.
# Remember the indentation (缩进) after the colon (冒号).
# syntax
# if condition:
# this part of code runs for true conditions
a = 3
if a > 0:
print('A is a positive number')
@ChuckleQu
ChuckleQu / 10_Day_Exercise.py
Created September 16, 2020 14:08
10_Day_Loops
# 1
n = 0
while n <= 10:
print(n)
n += 1
# 2
print()
n = 10
while n >= 0: