For the beginners who have learned a little bit of programming. Even Excel will help.
Install the 2 IDEs (Integrated Development Environment) below.
https://repl.it/languages/python3
https://www.codeschool.com/courses/try-python
https://www.learnpython.org/
Ex. 1: Calculate the average of several numbers.
- Let sum be the variable to accumate the numbers.
- Let count be the variable to store the count we process so far.
- Read each number one by one:
a) increase the sum by the number
b) increase count by 1- Finally, the average is sum/count
Ex. 2: Is x a prime:
(assume the x is an integer)
- If x is less then 2, it is not a prime.
- If x is 2, it is a prime.
- If x is divided by any interger from 2 ~ x-1, it is not a prime.
- It is a prime.
Ex. 3: Count the number of each letter in an English article.
- Let a, b, c, …, x, y, z be the variable which are used to stored the count of each letter.
- Read each charactor from the article one by one:
If the charactor is not an English letter, just skip it
else increase the value of the corresponding variable by 1.
Ex. 4: Make a histogram for the scores of the students in a class.
Ex. 5: Part of "master mind" - guess 1234 for answer 1357
for each digit d in the guessing number(1234 in this example):
compare the digit in the same position in the answer with d
if it is the same
get 1 A
else
compare the digit in the different 3 positions in the answer with d
# assume x is an integer
def is_prime(x):
if x < 2:
return False
if x == 2:
return True
for i in range(2,x): # range(a,b) means [a,b)
if x % i == 0:
return False
return True
A kid filled all the grids of a Sudoku, but does not know if it is correct.
How do you use your word to discribe the Sudoku rule?
Think a problem with your own language first. Then try to transform the idea into pseudo code, which uses variables, if-else, and looping. Finally, transform the pseudo code into the target programming language. Don't worry about the last step. You will learn how to code in Python after this lesson.
my_number = int(input())
my_string = input()
my_number = int(input("Please enter a number(1~100): "))
print(123)
print("the string")
print("no new line", end="")
a, b = 1, 2
print(a + b) # 3
c, d = "1",'2'
print(c + d)
print(1 / 3 == 0.3333333333333333) # True
print(1 == 1.00000000000000000001)
print(1 == 1.000000000001)
print(1 == "1")
print(None == 0)
x = 20
print(x*10)
x = "20"
print(x*10)
print(123 == 123)
print(123 == "123")
print(123 == int("123"))
print(str(123) == "123")
x, y = 10, 20
print("{}+{}={}".format(x,y,x+y))
print("{:<4}+{:<4}={:<4}".format(x,y,x+y))
if my_number == ans:
print("Correct!")
elif my_number > ans:
print("too large")
else:
print("too small")
while True:
x = int(input("input a number 1~100"))
if 0 <= x <= 100:
break
for i in range(1,20,2): # range(start, exclude end, each step)
print(i)
for i in range(10):
if i == 5:
continue
print(i, end="")
while True:
x = int(input("input a number 1~100"))
if 0 <= x <= 100:
break
*
**
***
****
*****
******
*******
********
*********
**********
* *
** **
*** ***
**** ****
**********
1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
...
4 * 4 = 16
4 * 5 = 20
4 * 6 = 24
4 * 7 = 28
4 * 8 = 32
...
9 * 5 = 45
9 * 6 = 54
9 * 7 = 63
9 * 8 = 72
9 * 9 = 81
Input the integer as the upper bound: 19
2
3
5
7
11
13
17
19
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing