sheet1 Cheat Sheet

A cheat sheet in English by Pop B
1,837 views 877 downloads 12 Feb 2016 History
3.7 avg · 0 ratings

Function

print()
show inform­ation that you want on the screen
int()
change number to be number integer
float()
change number to be decimal
input()
gain inform­ation from user
str()
a list of number, letter and symbols
len()
the length of the string
#
comment, no effect

vocabulary

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
gramma­r/s­tru­cture of lanquage
modulo
find the remainder
boolean
true/false

Math

==
equal to
!=
no equal to
<
less than
>
more than
<=
less than or equal to
>=
more than or equal to
%
modulo, find the remainder

addition

string + string
combine togethe
string + number
CRASH!
number + number
additional (math)

multip­lic­ation and exponents

string * number
combine that string
string * string
CRASH!
number * number
multiply (math)
string ** string
CRASH!
number ** number
Exponent (math)
string ** number
CRASH!

naming convention

Rule for giving name
-lettter
-number
-under­sco­re(_)
valid name
-mystr
-my3
-hello­_there
invalid name
-3my="h­i" --cannot start with number
-first name="h­i"
-first­-name

reverse word

While true:

word = input(­"­please enter a word")

index = 0

reverse = ' '


while int(index) < len(word):

reverse = word[i­ndex] + (reverse)

index = int(index) + 1


print ("Re­verse: ", reverse)

convert to binary

user_n­umber = ' '

while user_n­umber != ' 0 ' :
user_n­umber = input(­"­enter a number to convert to binary­")
number = int(us­er_­number)
binary­_string = ' '

while(­num­ber­>0):
remainder = number%2
binary­_string = str(re­mai­nder)+ binary­_string
number = number//2

print ("Binary string is", binary­_st­ring)

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.