Pinpin Python-3
Pinpin Python-3
==
Equal to
mystring = "hello"
ramdom_str =
!=
No equal to
print (mystring)
random.choice(strlist)
<
Less than
print(ramdom_str,strlist)
>
More than
first name?")
mylist =
<=
[1,10,100,2,20,200,'Pin','Anpan','B
>=
last name?")
ella']
ramdom_item =
lastname
random.choice(mylist)
Add
print (fullname)
print(ramdom_item,mylist)
Subtract
myvar1 = 1
Multiplication
myvar2 = 2
**
Exponent
if letternumber >len(fullname):
myvar3 = 3
//
random_var =
else:
random.choice(varlist)
letter = (
Text
fullname[letternumber] )
single quoted
'example'
print (letter)
double quoted
"example"
Functions
print()
if numberletter >100:
input()
int()
len()
float()
str()
Comment, no effect
varlist = [myvar1,myvar2,myvar3]
print(random_var,varlist)
10 [1, 10, 100]
200 [2, 20, 200]
Bella ('Pin', 'Anpan', 'Bella')
2 [1, 10, 100, 2, 20, 200, 'Pin', 'Anpan', 'Bella']
3 [1, 2, 3]
bacon()
def bacon():
print("hello it's bacon")
numberletter )
print("line 2")
hello
print("line 3")
print("line 4")
return
bacon()
bacon()
bacon()
hello it's bacon
List Random
line 2
import random
line 4
line 3
intlist = [1,10,100]
random_int =
line 2
random.choice(intlist)
line 3
print(random_int,intlist)
fplist = [2,20,200]
ramdom_fp = random.choice(fplist)
print(ramdom_fp,fplist)
line 4
hello it's bacon
line 2
line 3
line 4
strlist = ('Pin','Anpan','Bella')
By pinpin
Sponsored by CrosswordCheats.com
cheatography.com/pinpin/
Page 1 of 4.
http://crosswordcheats.com
Vocabulary
Variable
String
print(decoration + str(text) +
decoration)
return
Integer
Example
myprintnew(1, "+++")
number
myprintnew('hello','-=-=-=-=-=-
Float
=-=-=')
number
myprintnew(1, "@@@@@@@")
Syntax
+++1+++
Modulo
print (int(1.5)) 1
-=-=-=-=-=-=-=-=hello-=-=-=-=-=-=-=-=
Boolean
True / False
print (int(2)) 2
@@@@@@@1@@@@@@@
area of a triangle
def areaofTriangle(b, h):
mystr name
Naming Conventions
Rules for naming variables:
- letters
area = 0.5 b h
- numbers
return area
- underscores (_)
- my3
Hello_there
is',areaofTriangle(user_base,
Invalid names:
user_height))
def volumeofPrism(b,h,l):
volume = areaofTriangle(b, h)
mystr = Hi
*l
return volume
user_lenght = float(input('Enter
Sponsored by CrosswordCheats.com
cheatography.com/pinpin/
Page 2 of 4.
http://crosswordcheats.com
_var1
maxvalue (cont)
_var1 = 1
index = 0
_var1 = 3
is',max3(12222,5,10))
_var1 + 100
print(_var1)
is',max3(12222,164.3415645,12134856
1240))
reverse =''
while index < len(word):
reverse = word[index]+ reverse
index = index + 1
print ("Reverse: ",reverse)
Please enter your name: Timmy
Reverse: ymmiT
myprint(text)
def myprint(text):
maxvalue = mylist
return
return maxlist
myprint(1)
mylist =
myprint("hello")
[21365741,2135416,2,54131,1.1515]
myprint(2.5)
print(maxlist(mylist))
1
hello
maxvalue
2.5
def max2(num1,num2):
maxvalue = num1
areaOfCircle(r)
def areaOfCircle(r):
maxvalue = num2
if r <= 0:
return "Error: invalid
return maxvalue
print('The largest number
is',max2(2,3))
radius"
pi = 3.1415
area = pi r * 2
is',max2(12222,10))
return area
def max3(num1,num2,num3):
string * string
crash
number *
math - multiply
number
string ** string
crash
number **
math - multiply
number
string **
crash
number
Addition
string + string
combine together
string + number
crash
number + number
math-addition
Conditionals
user_radius = float(input("Enter
maxvalue = num1
the radius:"))
If.....
maxvalue = num2
:then.....
areaOfCircle(user_radius))
else.......
maxvalue = num3
return maxvalue
print('The largest number
is',max3(1,5,10))
By pinpin
Sponsored by CrosswordCheats.com
cheatography.com/pinpin/
Page 3 of 4.
http://crosswordcheats.com
area of a triangle
while......
index = 0
While
loops forever
True
for each
item in
name of
list
Big or small code
area = 0.5 b h
return area
user_base = float(input('Enter the
print (item)
user_height = float(input('Enter
shoes
bags
shirts
is',areaofTriangle(user_base,
pants
user_height))
shoes
def volumeofPrism(b,h,l):
print (mystr.upper())
bags
print (mystr.lower())
shirts
print (mystr.capitalize())
print (mystr.title())
pants
printDefinitions
HELLO THERE
hello there
volume = areaofTriangle(b, h)
*l
return volume
user_lenght = float(input('Enter
the length of the prism: '))
print('The volume of the prism
Hello there
def printDefinitions(word):
Hello There
if word =="variable":
print ('....')
number: ")
number = int(user_number)
countdown_string = ''
while number > 0:
countdown_string =
countdown_string+ str(number)
print ('....')
number = number-1
print (countdown_string)
print ('....')
elif word =="function call":
mystr = "Hello"
letter_num = 0
while letter_num < len(mystr):
print (mystr[letter_num])
letter_num = letter_num + 1
print ('....')
print ('....')
else:
print("unknown word")
user_height, user_lenght) )
elif word=="string":
is',volumeofPrism(user_base,
return
while True:
user_input = input("Enter word:
")
printDefinitions(user_input)
return number*2
print (doubleIt(3))
print (doubleIt(doubleIt(4)))
myvar = 12
myvar= doubleIt(myvar)
myvar= doubleIt(myvar)
print(myvar)
6
16
48
Enter word:
H
e
l
l
o
By pinpin
Sponsored by CrosswordCheats.com
cheatography.com/pinpin/
Page 4 of 4.
http://crosswordcheats.com