This is a draft cheat sheet. It is a work in progress and is not finished yet.
Vocabulary
Variable |
Hold the value |
String |
A list of character such as, number, symbol, letters |
Integer |
Whole number the number that can count |
Float |
The decimal number.ex 1.00 1.01 2.89 |
Boolean |
True / False |
Modulo |
Find the Remainder. Ex 5%4 =1 6%4 = 2 |
Example 2
name = input("Please enter your name : ")
age = input("Please enter your age : ")
height = float(input("Please enter your height(Cm) : "))
height /= 100
weight = float(input("Please enter your weight(Kg) : "))
gender = input("Please enter your gender : ")
BMI = (weight / height) / height
print (BMI)
message = ("Dear, %s your BMI is %s " % (name, BMI))
print (message)
from datetime import datetime
date = datetime.now()
date = "%s / %s" % (date.month, date.year)
print (date)
concatenate = "Dear %s, your BMI is %s as of %s." % (name, BMI, date)
print (concatenate)
x = -(-(-2)) == -2 #true
x = 3 ** 3 >= 26 #true
x = 10 % 9 != 1 #false
x = 33 <= 10 * 3 + 2 #false
x = 3
y = x + 3
print (y)
name = "Task"
age = 15
print ("Hello %s, I hear your age is %s " % (name, age))
# omsap aom 1008 (Owner) |
|
|
Function
Print() |
Display the information on the screen |
Input() |
Ask the user for the information |
int() |
Convert the value into integer |
float() |
Change the number into decimal point |
str() |
To make the number variable or somethings to be the symbol |
len() |
The length of the string |
# |
To and the comment, just add not effect the command |
"""______""" |
Multiple line comment |
Symbol
== |
Equal to |
!= |
Not equal to |
< |
Less than |
> |
More than |
<= |
Less than or equal to |
>= |
More than or equal to |
+ |
Add |
- |
Subtract |
* |
Multiply |
/ |
Divide |
** |
To the power(exponent) |
% |
Modulo |
.upper() |
Upper letter |
.lower() |
Lower letter |
.capitalize() |
Capital |
.title() |
First letter capital |
|
|
Example 1
# Omsap kongamornpinyo
"""1008 I am very kind"""
x = 3
y = x + 1
print (y**x)
print ((str(x) + str(y)))
name = input ("Name : ")
surname = input("Surname : ")
fullname = name + surname
print (("Welcome to Computer Science : "), (name), (surname[0].upper()))
letter = input ("Enter letter number : ")
myletter = int(letter)
print (fullname[myletter])
lettercount = input ("How many times shนuld I print this letter?: ")
mylettercount = int(lettercount)
print ((fullname[myletter])* (mylettercount)) |
|