Today, I learnt:
3:Comments and Quotes
Python ignore program after # sign.
It usually use explain parts of the program for me or other people.
If you want to print " this sign, you put \ (backslash) before " or ' .
4:Types
The word is 'str', whole number is 'int', decimal number is 'float'.
5:Input
The input() function takes no srguments and always gives back a 'str'.
Monday, August 25, 2014
Wednesday, August 20, 2014
Computer Science Circles (0:Hello!~2:Function)
I record about computer programming. I learn from Computer Science Circles.
Example: Run-time error
print(1/0)
Example: Syntax error
print(Hello)
Function
Example:
print(max(1,2,3))
This command will print 3
+plus - minus *times /divide
http://cscircles.cemc.uwaterloo.ca/0-introduction/
I had done excise are:
0:Hello!
1:Variable
1E: Error
2:Function
[print] is Python code to send messages to output.
Example: print("Hello")
( ) This is print command to use what you want to print
" " If there aren't " " mark, Hello is meant to be command
Example:Variable
x=5 (x=5)
x=x+x (x=5+5=10)
x=x-5 (x=10-5=5)
So, x=5 after execute these command
Error
A run-time error happens when Python understands what you are saying, but runs into trouble when following your instructions. A syntax error happens when Python cannot understand what are you saying.Example: Run-time error
print(1/0)
Example: Syntax error
print(Hello)
Function
Example:
print(max(1,2,3))
This command will print 3
+plus - minus *times /divide
Computer Science Circle (2E:Extra Practice)
I learnt 2E: Extra Practice today. It extra excise in 2:Function.
Sorting Scramble was really difficult question. I took almost class time for this question.
I wanted x=smallest, y=next smallest and z=largest number
tmp=max(x,y)
x=min(x,y)
y=tmp
tmp=max(y,z)
y=min(y,z)
z=tmp
tmp=max(x,y)
x=min(x,y)
y=tmp
After execute these command, x=smallest, y=next smallest and z=largest number every time.
Sorting Scramble was really difficult question. I took almost class time for this question.
I wanted x=smallest, y=next smallest and z=largest number
tmp=max(x,y)
x=min(x,y)
y=tmp
tmp=max(y,z)
y=min(y,z)
z=tmp
tmp=max(x,y)
x=min(x,y)
y=tmp
After execute these command, x=smallest, y=next smallest and z=largest number every time.
Subscribe to:
Posts (Atom)