Show Menu
Cheatography
This is a draft cheat sheet. It is a work in progress and is not finished yet.

Addition

string + string
combine togeth
string + number
crash
number + number
math-a­ddition

Multip­­li­c­ation and Exponents

string * number
combine that string multiple times
string * string
crash
number * number
math - multiply
string ** string
crash
number ** number

Condit­ionals

if else
If the statement is true then do command under then else do command under else.
elif
Similar to if else, but elif allows for more conditions (The keyword ‘elif‘ is short for ‘else if’)
for loop
For loop will loop though every element of the set of elements
while loop
Loop Contains 3 basic parts: 1. initial value 2. ending condition 3. update

Convert to binary Python (cont)

user_number = ' '
while user_number != '0' :
user_number = input ("Enter a
number to convert to binary")
number = int(user_number)
binary_string = ' '
while (number > 0):
remainder = number%2
binary_string = str(remainder)
+ binary_string
number = number // 2
print ("Binary string is",
binary_ string)

User input

user_input = input(­"­Enter a value: ")
 

Function

print() Show inform­­ation that you want on the screen

int() Change number to be number integer float() Change number to be decimal number

input() Gain inform­­ation from user

str() A list of number, letter and symbols

len() The length of the string # Comment, no effect

# Comment, no effect

code

print (name.u­pp­er())
print (name.l­ow­er())
print (name.c­ap­ita­lize())
print (name.t­it­le())

Excample

Print (2)
integer
Print (2.5)
floating point
Print ("Hello)
string
Print (mystr)
variable
print (int(1.5)) = 1
print (int("2')) = 2
Modulo­/Re­mainder %
print (4%2) → 0
print (30%7) → 2

Area of circle Python


#Ask the user for a radius of a
circle
while True:
user_radius = input("Please
enter the radius of the circle:")
radius = float(user_radius)
pi = 3.1415
area = (piradius*2)
print("The area of the circle
is", area
 

Vocabulary

variable
holds a value and can be changed
string
a list of characters such as numbers, letters, symbols
Floating point
decimal number
Integer
is a whole number (not a fractional number) that can be positive, negative, or zero
Boolean
True or false
*
Called star or asterix symbol
( )
Called index
**
power
<
less than
>
more than
<=
less than or equal
>=
more than or equal
=
operator / assigns a value
==
compare two values Answer is True or fulse
!=
no equal to
%
modulo, find the remainder
function
blocks of reusable code
Constants
Data stored in memory that cannot be changed after declar­ation
Compile
Run the program
Debug
Check the program for errors
syntax
Gramma­r/S­tru­cture of language

Reverse Word

while True:
word = input("Please enter a word")
index = 0
reverse = ' '
while int(index) < len(word):
reverse = word[index] + (reverse)
index = int(index) + 1
print ("Reverse: ", reverse)