|
Variable
|
hold a value and can be change
|
|
String
|
a list of character such as number, letter and symbols
|
|
Integer Number
|
whole number/ counting number
|
|
float number
|
the number in decimal
|
|
syntax
|
grammar/ structure of language
|
|
modulo
|
find the remainder
|
|
boolean
|
true/ flase
|
|
string + string
|
combine together
|
|
string + number
|
CRASH!
|
|
number + number
|
Addition (math)
|
|
string* number
|
combine that string
|
|
string* string
|
CRASH!
|
|
number* number
|
Multiply (Math)
|
|
string ** string
|
CRASH!
|
|
number ** number
|
Exponents (Math)
|
|
string ** number
|
CRASH!
|
|
print()
|
show information that you want on the screen
|
|
int()
|
change number to be number integer
|
|
float()
|
change number too be decimal number
|
|
Input()
|
gain information from user
|
|
str()
|
a list of number, letter and symbols
|
|
len()
|
the length of the string
|
|
#
|
comment, no effect
|
_varl = 1
_varl = 3
_varl + 100
print(_varl)
def bacon(): #use the keyword def and end with a colon:
print("hello it's bacon")
return
bacon()
bacon()
bacon()
bacon()
bacon()
def bacon():
print("hello it's bacon")
print("line 2")
print("line 3")
print("line 4")
print("line 5")
print("line 6")
print("line 7")
print("line 8")
return
bacon()
bacon()
bacon()
def myprint(text): #single parameter
print ("***" + str(text) + "***")
return
myprint(1)
myprint("hello")
myprint(1+2)
def myprint2(text, decoration):
print(decoration + str(text) + decoration)
return
myprint2(12312321312, "++++")
myprint2("hello", "<<>>")
def doubleIt(number):
return number * 2
myvar = 2
myvarDouble = doubleIt(myvar)
print(doubleIt("hello"))
myvar = doubleIt(doubleIt(3)) #same as doubleIt(6)
print (myvar)
def sumIt(num1, num2):
return num1 + num2
print(sumIt("a", "b"))
print(sumIt(2,3))
def areaOfCircle (radius):
pi = 3.1415
area = pi * radius**2
return area
user_radius = input('Enter the radius: ')
radius = float(user_radius)
print("The area of the circle is", areaOfCircle(radius))
def areaOfCircle(r):
if r <= 0:
return "Error: radius <= 0"
pi = 3.1415
area = pi * r ** 2
return area
user_radius = input("Enter the radius: ")
radius = float(user_radius)
print ("The area of the circle is", areaOfCircle(radius))
|
= =
|
equal to
|
|
!=
|
no equal to
|
|
<
|
less than
|
|
>
|
more than
|
|
<=
|
less than or equal to
|
|
>=
|
more than or equal to
|
|
%
|
Modulo, find the remainder
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.