0% found this document useful (0 votes)
5 views

iamtle_python

Uploaded by

eyanft3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

iamtle_python

Uploaded by

eyanft3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Cheat Sheet

by Iamtle via cheatography.com/25873/cs/6991/

Function List Random (cont)

print() Display an inform​ation on the screen '''SHOPPING_LIST= varlist = [myvar1, myvar2, myvar3]

int() Change number to an integer ['bags','shirts','pants'] random_var =


list_num=0 random.ch​oic​e(v​arlist)
float() Change number to an decimal number
while list_num < print (rando​m_var) #print the
input() Ask for the inform​ation from the user
len(sh​opp​ing​_list) entire list and the random item
str() A list of number, letter and symbols
​ ​ ​ ​pri​nt(​sho​ppi​ng_​lis​t[l​ist​_num])
len() Length of the string
​ ​ ​ ​lis​t_num = list_num + 1 Operations
# Comment for item in in shopping lost:
== equal to
''' ''' Multiple Line Comment ​ ​ ​ ​print (item)
!= no equal to

Reverse A Word < less than


Random
> more than
while True: import random
​ ​ word = input(​​"​P​lease enter a <= less than or equal
# Create a list of integers
word") % Modulo, Calculate for Remainder
intlist = [1,2,3,4]
​ ​ ​index = 0 random_int = + Add
​ ​ ​reverse = ' ' random.ch​oic​e(i​ntlist) - Subtract
#while int(index) < len(word): print (rando​m_int) #print the * Multip​lic​ation
# reverse = word[i​​ndex] + entire list and the random item / Division
(reverse) # Create a list of floating point
** Exponent
# index = int(index) + 1 numbers
for letter in word: fplist = [0.2,0.3,0.4] Convert To Hex
​ ​ ​ ​ ​reverse = letter + reverse random_fp = random.ch​oic​e(f​plist)
while True:
print ("Re​​verse: ", reverse) print (rando​m_fp) #print the
​ ​ ​ ​use​r_n​umber = input(​"​Please
entire list and the random item
enter your number: ")
Countdown Code # Create a list of strings
​ ​ ​ ​number = int(us​er_​number)
strlist = ("AB​C","D​EF",​"​GHI​")
​ ​ ​ ​hex​_string = ''
user_n​umber = input(​"​Please enter a number: random_str =
​ ​ ​ ​while (number > 0 ):
") random.ch​oic​e(s​trlist)
​ ​ ​ ​ ​ ​ ​ ​rem​ainder = number % 16
number = int(us​er_​number) print (rando​m_str) #print the
countd​own​_string = '' ​ ​ ​ ​ ​ ​ ​ if remainder == 10:
entire list and the random item
while number > 0: ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​hex​_string = "​A" +
# Create a list of integers and
countd​own​_string = countd​own​_string + hex_string
floating point numbers and strings
str(nu​mber) ​ ​ ​ ​ ​ ​ ​ elif remainder == 11:
number = number - 1 mylist = (2,3,0.4,​"​Hel​lo")
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​hex​_string = "​B" +
print (count​dow​n_s​tring) random​_item =
hex_string
random.ch​oic​e(m​ylist)
​ ​ ​ ​ ​ ​ ​ elif remainder == 12:
print (rando​m_item) #print the
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​hex​_string = "​C" +
entire list and the random item
hex_string
# Create a list of the following
​ ​ ​ ​ ​ ​ ​ elif remainder == 13:
variables
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​hex​_string = "​D" +
myvar1 = 1
hex_string
myvar2 = 2
​ ​ ​ ​ ​ ​ ​ elif remainder == 14:
myvar3 = 3
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​hex​_string = "​E" +
hex_string

By Iamtle Published 5th February, 2016. Sponsored by CrosswordCheats.com


cheatography.com/iamtle/ Last updated 11th February, 2016. Learn to solve cryptic crosswords!
Page 1 of 2. http://crosswordcheats.com
Python Cheat Sheet
by Iamtle via cheatography.com/25873/cs/6991/

Convert To Hex (cont) Example Of Codes Guessing Game (cont)

​ ​ ​ ​ ​ ​ ​ elif remainder == 15: 2 – integer ​ ​ ​ ​print ("Wo​rd:​"​,(w​ord))


​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​hex​_string = "​F" + 2.5 – floating point ​ ​ ​ ​gue​ss_word = input(​"​Guess a
Print (“Hello”) – string
hex_string word: ")
mystring = 123 – variable
​ ​ ​ ​ ​ ​ ​ elif remainder < 10: ​ ​ ​
Print (mystr​​,”​H​i​”,​​2,1.0) -- commas
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​hex​_string = ​ ​ ​ if guess_word == random​_word:
mystr = “Hi”
str(re​mai​nder) + hex_string mystr ← variable name ​ ​ ​ ​ ​ ​ ​ ​print ("That's Correct
​ ​ ​ ​ ​ ​ ​ ​number = number // 16 “Hi” ← value that can be change Guess!​")
​ ​ ​ ​print ("He​xad​eimal string is print (int(1.5)) → 1 ​ ​ ​ ​ ​ ​ ​ ​print ("--​---​---​---​---​--
0x"+ hex_st​ring) print (int(“2”)) → 2 -​---​---​---​---​---​---​---​---​---​---​--
print (float(1)) → 1.0
-​---​-")
Modulo​​/R​e​m​ainder %
Area Of The Circle Code ​ ​ ​ ​ ​ ​ ​ ​score = score + 100
print (4%2) → 0
print (30%7) → 2 ​ ​ ​ ​ ​ ​ ​ ​print ("Sc​ore​:",(​score))
while True:
​ ​ ​ ​ ​ ​ ​ ​ran​dom​_word =
​ ​ ​ ​use​r_r​adius = input(​"What is
your radius of a circle? ") Multip​lic​ation And String random.ch​oic​e(word)
​ ​ ​ ​else:
​ ​ ​ ​radius = float(​use​r_r​adius) String * Number
​ ​ ​ ​ ​ ​ ​ if guess_word !=
​ ​ ​ pi = float(​3.1415) Ex. String * 5 = String String
random​_word:
​ ​ ​ area = (pi) (radius) * 2 String String String
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​chances = chances - 1
​ ​ ​ ​pri​nt(​"The area of the String * String = Crash !
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​print ("Ch​ances
circle​", area) Number * Number = Multiply (Math)
Remain​ing​:",c​hances)
Ex. 5 * 4 = 20
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ if guess_word in word:
Upper and Lower Case String ** String = CRASH!
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​print
Number ** Number = Exponent (Math)
("So​rry​,Wrong Choice​!")
name = "one two" Ex. 5**2 = 25
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​print ("--​---​---​--
String ** Number = CRASH!
-​---​---​---​---​---​---​---​---​---​---​--
print (name.u​​p​p​er()) → ONE TWO
print (name.l​​o​w​er()) → one two -​---​---​---​-")
Guessing Game
print (name.c​​a​p​i​ta​​lize()) → One two ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​else:
print (name.t​​i​t​le()) → One Two import random ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​print ("Sorry That
game_over = 1 is not even in the list")
Vocabu​larty chances = 5 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​print ("--​---​---​--
score = 0 -​---​---​---​---​---​---​---​---​---​---​--
Variable reserved memory locations to store
word =
values. This means that when you -​---​---​---​-")
create a variable you reserve some ['Dog'​,'C​at'​,'F​ish​','​Pig​','​Ele​phant ​ ​ ​ ​ ​ ​ ​ if chances == 0:
space in memory '] ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​gam​e_over = 0
String A list of character such as number, random​_word = random.ch​oic​e(word) ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​print ("Game Over!")
letter and symbols while game_over != 0: ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​print ("The word
Boolean True/False was"​,(r​and​om_​word))
Integer Whole Number or Counting Number ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​print ("Final Score:​"​,
Number (s​core))

Syntax Grammar of Python ​ ​ ​ ​ ​ ​ ​

Floating Number in Decimal ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​

Point

By Iamtle Published 5th February, 2016. Sponsored by CrosswordCheats.com


cheatography.com/iamtle/ Last updated 11th February, 2016. Learn to solve cryptic crosswords!
Page 2 of 2. http://crosswordcheats.com

You might also like