Category: Python

python code

Geometric Series with Python

Background Story : There were a couple of mathematicians went to a bar, the first guy ordered one beer, the second guy asked for 1/2 of a beer, the third guy asked for 1/4 of a beer, the fourth ordered 1/8 of a beer, and so on… The hot bartender rolled her eyes, poured two beers, and says, “Here, you…

The Chinese Remainder Theorem

Chinese Remainder Theorem  Background Story: back in the Han dynasty, there is a  famous General Han Xin. In order to prevent the spy in the army to detect the number of his soldiers, he used an advanced Counting System (韩信点兵).  Instead off directly counting from 1 to n, he asked his soldiers to number off from 3 times. First time 1…

Python Little Goal 2

  Python Day 8 Problem 1: Factorial  Write a factorial function that takes a positive integer,  N as a parameter and prints the result of  N! Solution: def factor(n): a=1 for i in range (1,n+1): a=a*i print(a) factor(3) 6 factor(5) 120   Problem 2: Age Create a function age() should perform the following conditional actions: If n is between 0 to 12, print Young. If 13 and 19,…

Python Little Goal 1

Python Day 7 Problem 1: Given an array of integers, find the sum of its elements. For example, if the array ar=[1,2,3] , so return 6 . Solution: import math ar=[1, 2, 3, 4, 10, 11] def simplesumarray(ar): return(sum(ar)) simplesumarray(ar) 31   Problem 2: Given the meal price ( meal), tip percent (tip), and tax percent ( tax) for a meal, find and print the meal’s total integer cost: Solution:…

Linear Optimization with Python 2

  Python Day 6: Linear Optimization with Paper Company Last time we did a Pirelli Glass Linear Optimization, it considered a simple problem, because it has only 2 variables.What should we do if there are more variables and with much more complexed constrain systems? Problem: Nancy Grant is the owner of Coal Bank Hollow Recycling company, there is two Recycling Process.

Linear Optimization with Python 1

Python Day 5: Linear Optimization problem  Side Story:  Excel Solver is an excellent tool for Linear Optimization problems, but we need to pay for this platform. In addition, 5 asked me with an extremely surprised facial expression: “What kind of data scientists would use Excel? “ 😱😱😱 Therefore we will introduce how to use Python to solve a Linear Optimization Problem,…

Collatz Conjecture

  Python Day 4: Collatz Conjecture Some of the students used to ask me, why do we have to learn calculus? I told them because if they are good at calculus then they may good at abstract algebra and number theory, and eventually can be the front page of the People’s Magazine like Andrew Wiles. (Andrew Wiles proved Fermat’s Last Theorem).

Fun Numbers

Python Day 3: Finding Fun Numbers All the maths fans know the story about 1729, the Ramanujan Number. One day Hardy visited Ramanujan in the hospital and said he took a taxi with a boring licence number, 1729. Ramanujan said:  it is a very interesting number; it is the smallest number expressible as the sum of two cubes in two different ways.

Christmas Tree

  Python Day 2: Christmas Tree Last time I went to pick up a real Christmas tree was with Little Charles. It was a really big tree, I have to hold it on the way back. This year I don’t have a real tree, so I made a Christmas tree with Python.   Code: import matplotlib as mpl from mpl_toolkits.mplot3d…

Social media & sharing icons powered by UltimatelySocial