Show Menu
Cheatography

kimmy computer Cheat Sheet by

1

input( )
show
print( )
show answer
int( )
number
str( )
float( )
change number to decimal
while
loop
if: elif else:
Boolean
True/False
len( )
length of
in
in
import random
import
random.ch­oic­e(m­ylist)
random in mylist
while True
forever loop
range()
range(­5)=­0,1­,2,3,4

5 Reverse

word = input(­"­Please enter your name: ")
index = 0
reverse = ' '
while index < len(word):
reverse = word[i­ndex] + reverse
index = index +1
print ("Re­verse: "­,re­verse)

area

def areaof­ell­ips­e(r­adi­us1­,ra­dius2):
-pi=3.1415
-area=piradius1radius2
-return area
area1=­are­aof­ell­ips­e(2,3)
print(­area1)

evenodd count

evenco­unt=0
oddcount=0
while True:
-num=i­nt(­inp­ut(­"­Enter a positive intege­r:"))
-if num<0:
--prin­t("Even number­s:",­eve­ncount)
--prin­t("Odd number­s:",­odd­count)
--break
-else:
--if(n­um%­2)==0:
---eve­nco­unt­=ev­enc­ount+1
--else:
---odd­cou­nt=­odd­count+1
 

2

+
add
-
subtract
/
divide (ans in float/­dec­imal)
**
power
*
multiply
=
assign a value
==
compare 2 values
!=
not equal to
>
more than
<
less than
>=
more than or equal to
<=
less than or equal to
:
for user to enter
#
comments (do not show)
%
remainder
//
divide(ans in integer) 2.5=2
3(3+1)
CRASH because no *. Have to be
 
3*(3+1)

6 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 (number > 0):
remainder = number%2
binary­_string = str(re­mai­nder) + binary­_string
number = number//2
print ("Binary string is", binary­_st­ring)

fibonacci

num1=0
num2=1
fibona­cci­=nu­m1+num2
myoutp­ut=­"­0,1­"
while fibona­cci­<50:
-myout­put­=my­out­put­+", "­+st­r(f­ibo­nacci)
-num1=num2
-num2=­fib­onacci
-fibon­acc­i=n­um1­+num2
print(­myo­utput)
 

hex

while True:
-user_­num­ber­=in­put­("Enter a number­:")
-num=i­nt(­use­r_n­umber)
-hex_s­tri­ng=­"­"
-while­(nu­mbe­r>0):
--rema­ind­er=­num­ber%2
--if remain­der­==10:
---rem­ain­der­="A"
--elif.............................
--hex_­str­ing­=st­r(r­ema­ind­er)­+he­x_s­tring
--num=­num//16
-print­("He­xad­ecimal string is 0x"+­hex­_st­ring)

3

naming consention
letters
a,A,_
 
numbers
 
unders­core_

4

string­+string
fusion
string­+number
crash
number­+number
normal math
string­*string
crash
string­*number
fusion
number­*number
normal math
string­**s­tring
crash
string­**n­umber
crash
number­**n­umber
normal math

while

0
mystri­ng=­"­"
01
count=0
012
while count<5:
0123
-mystr­ing­=my­str­ing­+st­r(c­ount)
01234
-print­(my­string)
 
-count­=co­unt+1

while

mylist­=[1­,2,3]
num=0
while num<le­n(m­ylist):
-print­(my­lis­t[num])
-num=num+1
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.