Show Menu
Cheatography

SongInwZa's cheat Cheat Sheet by

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

Addition

string + string
Combine together
string + number
CRASH!
number + number
Addition (Math)

Function- maxvalue

# name: max2
# arguments: num1, num2
# return: the largest value
def max2(num1, num2):
    maxvalue = num1

    if num2 > num1:
        maxvalue = num2

    return maxvalue

print(max2(10, 9))
print(max2(1, 9))

# write a function that returns the largest of three values
# name: max3
# arguments: num1, num2, num3
# return: the largest value
def max3(num1, num2, num3):
    maxvalue = num1

    if num2 > maxvalue:
        maxvalue = num2

    if num3 > maxvalue:
        maxvalue = num3

    return maxvalue

print(max3(2, 12, 4))
print(max3(19, 9, 17))

# write a function that returns the largest number in a list
# name: maxlist
# arguments: list
# return the largest value in the list
def maxlist(list):

    # loop through the list

    return  maxvalue
numlist = (1, 2, 3, 4, 5, 99)
print(maxlist(numlist))
 

Vocabulary

Variable
Hold a value and can be change
String
A list of character such as number, letter and symbols
Integer number
Whole number­/co­unting number
Floating point
The number in decimal
Syntax
Gramma­­r/­S­t­ru­­cture of lauguage
Modulo
Find the remainder
Boolean
True/False

Multip­­­l­i­c­­ation and Exponents

string * number
Combine that string
string* string
CRASH!
number * number
Multiply (Math)
string ** string
CRASH!
number ** number
Exponent (Math)
string ** number
CRASH!
 

Math

==
equal to
!=
no equal to
<
less than
>
more than
<=
less than or equal to
>=
more than or equal to
%
Modulo, Find the remainder

Reverse Word

while True:
word = input(­­"­P­lease enter a word")
index = 0
reverse = ' '

while int(index) < len(word):
reverse = word[i­­ndex] + (reverse)
index = int(index) + 1

print ("Re­­verse: ", reverse)

Convert to binary

Convert to binary
user_n­­umber = ' '

while user_n­­umber != ' 0 ' :
user_n­­umber = input ("Enter a number to convert to binary­­")
number = int(us­­er­_­n­umber)
binary­­_s­tring = ' '

while (number > 0):
remainder = number%2
binary­­_s­tring = str(re­­ma­i­n­der)+ binary­­_s­tring
number = number//2

print ("Binary string is", binary­­_s­t­ring)
 

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.