|
print()
|
Show the information that you want on screen
|
|
int()
|
Change number to be number integer
|
|
float()
|
Change number to be decimal number
|
|
input()
|
Gain information from user
|
|
str()
|
A list of number, letter and symbols
|
|
len()
|
The length of the string
|
|
#
|
Comment, no effect
|
|
string*number
|
combine that string
|
|
string*string
|
CRASH
|
|
number*number
|
Multiply
|
|
string**string
|
CRASH
|
|
number**number
|
Exponent
|
|
string**number
|
CRASH
|
user_number= ' '
while user_number ! = '0'
user_number = input ("Enter a number to convert to binary")
number=int(user_number)
binary_string= ' '
while (number>0):
remainder = number%2
binary_string=str(remainder)+binary_string
number=number//2
print("Binary string is ,binary_string)
mystr = "Hello"
letter_num = 0
while letter_num<len(mystr):
print(mystr[letter_num])
letter_num=letter_num+1
H
E
L
L
O
name="tim GIRARD"
print(name.upper())
def areaOfcircle(radius):
if radius<=0:
return "Error invalid radius"
pi=3.1415
area = pi*radius**2
return area
user_radius = float(input("Enter the radius: "))
print ("The area of the circle is",areaOfcircle(user_radius))
def doublet(number):
return number * 2
print (doublet(3))
print (doublet(doublet(4)))
def printDefinitions(word):
if word == "variable":
print ("""A variable is the value that can be changed""")
elif word == "function":
print ("""A function is blog of code that we can reuse""")
elif word == "parameter":
print ("""A parameter is something is given in the function""")
elif word == "arguement":
print ("""A arguement is something is given in the function""")
elif word == "function call":
print ("""A function call is something that make the function runs""")
elif word == "string":
print ("""A string is character such as symbol, number""")
else:
print("unknown word")
return
while True:
user_input=input("Enter word:")
printDefinitions(user_input)
def areaOfTriangle(b,h):
area=0.5*b*h
return(area)
user_base = float(input('Enter the base of the triangle'))
user_height = float(input('Enter the height of the triangle'))
print('The area of the triangle is',areaOfTriangle(user_base,user_height))
def volumeOfPrism(b,h,l):
volume = areaOfTriangle(b,h)*l
return(volume)
user_base = float(input('Enter the base of the prism'))
user_height = float(input('Enter the height of the prism'))
user_length = float(input('Enter the length of the prism'))
print('The volume of the Prism is',volumeOfPrism(user_base,user_height,user_length))
def maxlist[list]
maxvalue = list[0]
for item in list:
if item > maxvalue:
maxvalue = item
return maxvalue
mylist = [1,2,3,4,55,66,777,0,1]
print(maxlist(mylist))
|
string+string
|
Combine together
|
|
string+number
|
CRASH
|
|
number+number
|
Addition
|
|
variable
|
Hold a value and can be changed
|
|
string
|
A list of character such as number,letter and symbol
|
|
integer number
|
whole number/ counting number
|
|
float number
|
the number in decimal
|
|
syntax
|
Grammar/Structure of language
|
|
Boolean
|
True/False
|
|
==
|
equal to
|
|
!=
|
no equal to
|
|
<
|
less than
|
|
>
|
more than
|
|
<=
|
less than or equal to
|
|
>=
|
more than or equal to
|
|
%
|
Modulo, Find the remainder
|
user_number=input("What number do you want to count down?")
numer=int(user_number)
countdown_string=' '
while number > 0
countdown_number= countdown_string+
str(number) + " "
number=number-1
#print(number)
print(countdown_string)
|
Rule for giving name
|
|
-letter
|
|
-numbers
|
|
-underscore
|
|
Valid name
|
|
-myStr
|
|
-my3
|
|
-Hello_there
|
|
Invalid name
|
|
-3my="hi" -- cannot start with number
|
|
-first number='hi'
|
|
-first-name
|
|
-first+name
|
import random
intlist= [1,2,3,4,5]
random_int = random.choice(intlist)
print(intlist,random_int)
fplist=[1.1,2.2,3.3,4.4,5.5]
random_fp= random.choice(fplist)
print(fplist,random_fp)
strlist=['opal','love','tientien']
random_str= random.choice(strlist)
print(strlist,random_str)
mylist=['tientien',1,5.5]
random_item=random.choice(mylist)
print(mylist,random_item)
myvar1=1
myvar2=2
myvar3=3
varlist=[myvar1,myvar2,myvar3]
random_var=random.choice(varlist)
print(varlist,random_var)
def myprint(text):
print("***"+str(text)+"***")
return
myprint (1)
myprint ("hello")
myprint (2.5)
def myprintnew(text, decoration):
print(decoration + str(text) + decoration)
return
myprintnew(1,"+++")
myprintnew ('hello','=-=-=-=-=-=-=-=')
reverse = ""
letter_num=0
user_input = input("type in a number")
while letter_num<len(user_input):
reverse = user_input[letter_num]+reverse
letter_num = letter_num+1
if reverse == user_input:
print ('parindorm')
else:
print ('not parindorm')
def max2(num1,num2):
maxvalue = num1
if num2 > maxvalue:
maxvalue = num2
return maxvalue
print (max2(4,5))
print (max2(33,5))
def max3(num1,num2,num3):
maxvalue = num1
if num2 > maxvalue:
maxvalue = num2
if num3 > maxvalue:
maxvalue = num3
return maxvalue
print (max3(1,2,3))
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.