Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Python Sheet Cheat Sheet

by pca221 via cheatography.com/25815/cs/6936/

Words

Calculate the Area of The Circle using def()

Variable

The information that can change

(cont)

String

The list of letters, numbers,

print("The area of the circle is ",

symboles

areaofcircle(user_radius))

The computer's grammar

Boolean

The information that contains true or

word = input("Enter the word: ")

Find the remainder

index = 0

Math Operations

!=
+

plus

3 != 2

to define that there has an 'if/else'


code in the other 'else' code

while

the code in 'while' section will be


repeated along to the condition

reverse = word[index] +
reverse

minus

3-2=1

times

3*2=6

divide

9/3=3

the remainder from divide

3%2=1

numbers

How To Create A List


def

index = index + 1

3+2=5

createlist(quitword):
print ("Keep entering words to

print ("Reverse: ", reverse)

add to the list")


print ("Quit when word =",

Calculating Fibonacci

quitword)

fbonacci = [0,1]

mylist = []

print(0)

while True:
user_word

print(1)

**

power

3 ** 2 = 9

<

less than

2<3

>

more than

3>2

<=

less than or equal to

2 <= 3 , 3

while

more than or equal to

len(fbonacci)

<

50:

fbonacci[len(fbonacci) - 2] +

if user_word

return mylist

fbonacci.extend([number])

duplicate = False for

print(number)

item in mylist:
if item == user_word:

>= 3
//

divide by not included

2//2000 =

Code & Functions

decimal point

int()

duplicate = True
if (duplicate == True):

convert the value into integer with no

print ("Duplicate

decimal place
Calculate the Area of The Circle using def()

print()

print the value

def

float()

change the value into number with

areaofcircle(r):

user_radius = foat(input("Enter
the Radius: "))

Word!")
else:
mylist.append(user_word

decimal point

pi = 3.1415
area = pi (r * 2)
return area

input("Please

== (quitword):

fbonacci[len(fbonacci)-1]

3 >= 2 , 3

ente0r a list item: ")

number =

<= 3
>=

elif

while index < len(word):


3 == 3

not equal to

things after 'if' is the code that works


when the variable is in the condition. If
worked.

false

equal to

if/else

How To Reverse

reverse = ''

==

things after # will not define as a code

not, the code in the 'else' code will be

Syntax

Modulo

Code & Functions (cont)

input()

use for want the user to type text in

len()

use for count the string

userlist = createlist("stop")

str()

change the value into string

import

import the code into the list

print (userlist)

By pca221

Published 15th February, 2016.

Sponsored by CrosswordCheats.com

cheatography.com/pca221/

Last updated 15th March, 2016.

Learn to solve cryptic crosswords!

Page 1 of 2.

http://crosswordcheats.com

Check The Word is Palindrome or Not


def isPalindrome(user_word):
length = len(user_word)
while length >= 1:
frstnumber = 0
frstletter

user_word[frstnumber]
lastletter

user_word[length - 1]
if frstletter ==
lastletter:

Guessing Game

Convert Integer into Binary (cont)

import random chance

binary = binary + remainderstr

= 3

if integer == 0:

score = 0

index = 0 binary2

while chance > 0:

= ''
while index < len(binary):

print ("Guessing game")

binary2 = binary[index] +

mylist =
['bowling','badminton','table

binary2
index = index + 1

tennis','basketball','golf']
print

("Words:"

print(binary2)

,mylist)

randomitem =
frstletter

== frstnumber + 1
lastletter == length 1

Math Operations

random.choice(mylist)
userguess = input("Please guess
a word: ")
if userguess == randomitem:

length = length - 2

print

("That's

Correct!

print ("Keep entering words to

("Sorry, wrong

number
string *

print ("Sorry, that is not


even in the list!")

user_word = input("Please enter a

print("Chance: ", chance) if


chance == 0:

break
else:

print ("Game Over! The word was


", randomitem)

length = len(user_word)

if isPalindrome(user_word)
== True:

crash

string *

combine

number

string many

number

multiply

numbers

string **

crash

string
crash

number
math

**

exponents

integer = input("Enter number: ")

number

(3) * (2) = (6)

number

number

integer

("I") * (3) = ("III")

times

Convert Integer into Binary

word is:", length)

(3) + (2) = (5)

string

string **

print ("Final Score:", score)

print ("The length of the

crash

chance = chance - 1 print

else:

print ("Quit when word = quit")

string +

together

chance = chance - 1

if user_word == ("quit"):

Working")

add numbers

print("Chance: ", chance)

not.")

word: ")

together

choice!")

while True:

("Working") = ("Stop

number

elif userguess in mylist:

return False

check that the word is palindrome or

("Stop ") +

string

number

Score: ", score)


return True else:

combine

string

score = score + 100

if length == 0 or
1:

string +

(3) ** (2) = (9)

int(integer)

remainder = integer binary


print (user_word, "is a

palindrome")

= ''
while

else:
print (user_word, "is
not a palindrome")

By pca221
cheatography.com/pca221/

integer !=

0:

remainder = integer % 2
integer = int(integer / 2)
remainderstr = str(remainder)

Published 15th February, 2016.

Sponsored by CrosswordCheats.com

Last updated 15th March, 2016.

Learn to solve cryptic crosswords!

Page 2 of 2.

http://crosswordcheats.com

You might also like