Cheatography
https://cheatography.com
Function
print() |
show information that you want on the screen |
int() |
change number to be number integer |
float() |
change number to be decimal |
input() |
gain information 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 |
grammar/structure 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) |
multiplication 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 |
-underscore(_) |
valid name |
-mystr |
-my3 |
-hello_there |
invalid name |
-3my="hi" --cannot start with number |
-first name="hi" |
-first-name |
|
|
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) |
convert to binary
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) |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment