Show Menu
Cheatography

Pimnada Cheat Sheet by

Addition

string­+string
combine together
string­+number
crash
number­+number
math-a­ddition

Multiple action and Exponents

string­*number
combine that string multiple times
string­*string
crash
number­*number
math-m­ultiply
string­**s­tring
crash
number­**n­umber
math-e­xpo­nents
string­**n­umber
crash

Math

==
equal to
!=
no equal to
<
less than
>
more than
<=
less than or equal to
>=
more than or equal to
 

Vocabulary

Variable
holds a value and can be changed
string
a list of characters such as numbers, letter­,sy­mbols
syntax
grammars or structure of language
float number
the number in decimal
input
gain inform­ation from user
print
to show inform­ation on the screen
syntax error
make impossible to the parse
mudole
the text for storing for python code
integer number
whole number or counting number
value
the number or string can be store in valuable

Function that allow a user to create a list

#create a function that allow a user to create a list

#function name: createList
#parameter: word
#returns the list

def createList(quitword):
    mylist = [] # create an empty list

    while True:
        #get the item from the user
        item = input('Please enter a list item: ')

        
        #when the user enters an item that is equal to quitword
        if (item == quitword)
        return mylist # return the list


        #check if the list already has that word
        duplicateword = False

        # figue out of the word is already in the list
        For myvar in mylist:
            if myvar == item:
                duplicaeword = True

        #...... loop through the list and compare each value

        if duplicateword == True: #duplicate is true
            print ('Duplicate word!')
        else:
            #add this item to the end of the list
            mylist.append(item)
#function call
mylist = createList("stop")
print(mylist)
 

Function

print()
displays inform­ation on the screen
input()
receives inform­ation from the user
int()
convert a value to an integer
float()
decimal number
str()
string­(wo­rd)­" "
#
commen­t(one line)
" " "
commen­t(many lines)

code

# receive the number from the user as a string
user_number = input("enter number: ")

#convert the user number to an integer
number = int(user_number)

#setup the countdown string
countdown_string = ''

while number > 0:
    countdown_string = countdown_string + str(number) + " "
    number = number - 1

print (countdown_string)




#get a number from the user
user_number = input("Please enter a number: ")

#convert to integer
number = int(user_number)

binary_string = ''
while (number > 0):#the number is greater than 0)
    remainder = number % 2
    binary_string = binary_string + str(remainder)
    number = number // 2
    #print (number)



#after the loop print the binary string
print ("Binary string is", binary_string)


#expected output - 5 = 101
#expected output - 3 = 11
#expected output - 2 = 10


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)




import random

intlist =[1,2,3,4]
random_int = random.choice(intlist)
print (random_int,intlist)

fplist =[1.1,2.2,3.3,4.4]
random_fp = random.choice(fplist)
print (random_fp,fplist)

strlist =(Best,Big,Boss,Bright)
random_str = random.choice(strlist)
print (random_str,strlist)

mylist = [1,1.1'Pimnada']
random_str = random.choice(mylist)
print (random_str,mylist) 

myvar1 = 1
myvar2 = 2
myvar3 = 3
varlist = [myvar1, myvar2, myvar3]
random_var =random.choice(varlist)
print (random_var,varlist)
 

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.