Show Menu
Cheatography

PatterPatter Cheat Sheet by

This is a description

Math

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

Area of circle

­"­" Python Intro Assignment #2 name student number "­­"­" #Ask the user for a radius of a circle user_r­­adius = input(­­"What is a radius of a circle­­?") #Convert the given radius to a floating point radius = float(­­us­e­r­_r­­adius) #Make a variable called pi pi = float(­­3.1­415) #Calculate the area of the circle using exponents area = pi(ra­­diu­­s*2) #Display the area of the circle to the user print ("The area of the circle is", area)
LOL

Countdown machine

user_n­­umber = input(­­"What number do you want to count down? ") number = int(us­­er­_­n­umber) countd­­ow­n­_­string = ' ' while number > 0: countd­­ow­n­_­number = countd­­ow­n­_­string + str(nu­­mber) + " " number = number - 1 #print­­(n­u­mber) print (count­­do­w­n­_s­­tring)

Print Name

name = "tim GIRARD­­" print (name.u­­p­p­er()) → TIM GIRARD print (name.l­­o­w­er()) → tim girard print (name.c­­a­p­i­ta­­lize()) → Tim girard print (name.t­­i­t­le()) → Tim Girard
LOL

Something cheap

print()
Show the inform­ation you want on the screen
input()
Change number to be number integer
str()
A list of number letter and symbol
float()
change number to be decimal number
len()
the length of the string
LOL there no such thing as note
 

Addition and multip­lic­ation and Exponet

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

Sort word per line

mystr = "­­He­l­l­o" letter_num = 0 while letter_num < len(my­­str): print (mystr­­[l­e­t­te­­r_num]) letter_num = letter_num + 1 H e l l o

sort of fruit list

fruits = [] #an empty list for number in range(5): user_fruit = input(­­"­P­lease enter a fruit") fruits.ap­­pe­n­d­(u­­ser­­_f­ruit) print ("Size of fruit list is", len(fr­­uits)) fruits.sort() for fruit in fruits: print ("Fruit: ", fruit)

sort of fruit list

fruits = [] #an empty list for number in range(5): user_fruit = input(­­"­P­lease enter a fruit") fruits.ap­­pe­n­d­(u­­ser­­_f­ruit) print ("Size of fruit list is", len(fr­­uits)) fruits.sort() for fruit in fruits: print ("Fruit: ", fruit)

apichat

Variable
Hold a value and can be change
string
a list of character such as number letter and symbol
Syntax
Grammar and structure of languge
Integer number
counting number
float number
the number in decimal
modulo
find the remainder
LOL
 

teaw cheat Example

print(2)
integer
Print(2.5)
floating point
Print (Hello)
string
print(­mystr)
variable
LOL

Namming Covention

Rule for giving name - letter - numbers - underscore _ Valid name - _myStr - my3 - Hello_­­there Invalid name - 3my=”hi” -- cannot start with number - first name=”hi” - first-name - first+name
LOL

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)
LOL

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)
LOL

Area of circle

Python Intro Assignment #2 name student number "­­"­" #Ask the user for a radius of a circle user_r­­adius = input(­­"What is a radius of a circle­­?") #Convert the given radius to a floating point radius = float(­­us­e­r­_r­­adius) #Make a variable called pi pi = float(­­3.1­415) #Calculate the area of the circle using exponents area = pi(ra­­diu­­s*2) #Display the area of the circle to the user print ("The area of the circle is", area)

Area of circle

Python Intro Assignment #2 name student number "­­"­" #Ask the user for a radius of a circle user_r­­adius = input(­­"What is a radius of a circle­­?") #Convert the given radius to a floating point radius = float(­­us­e­r­_r­­adius) #Make a variable called pi pi = float(­­3.1­415) #Calculate the area of the circle using exponents area = pi(ra­­diu­­s*2) #Display the area of the circle to the user print ("The area of the circle is", area)

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi
 

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.