|
Variable
|
Something that can be change
|
|
String
|
A list of characters
|
|
Integer Number
|
Whole number/counting number
|
|
Float Number
|
The number in decimal
|
|
Syntax
|
Grammar
|
|
Modulo
|
Remainder
|
|
Boolean
|
True&False
|
|
print()
|
display info. on the screen
|
|
input()
|
receives info from the user
|
|
int()
|
convert a value to an interger
|
|
float()
|
convert a value to a floating point
|
|
str()
|
convert a value to a string
|
|
len()
|
The length of the string
|
|
#
|
comment
|
|
if then else
|
if ... is True "then" will work or if it False then "else" will work
|
|
While: True
|
Forever Loop
|
|
for
|
Looping Forever
|
def max2(num1,num2):
if num1 > num2:
maxvalue = num1
elif num2 > num1:
maxvalue = num2
return maxvalue
#function call
print(max2(92,3))
print(max2(4,5))
def max3(num1,num2,num3):
maxvalue = num1
if num2 > maxvalue:
maxvalue = num2
elif num3 > maxvalue:
maxvalue = num3
return maxvalue
#function call
print(max3(92,5,6))
print(max3(8,9,7))
print(max3(99,40,49))
def maxlist(list):
maxvalue = list[0]
for num in list:
if maxvalue < num:
maxvalue = num
return maxvalue
mylist = 3,5476,134,8,451,87
print (maxlist(mylist))
|
Rules for giving name
|
|
-letter
|
|
-numbers
|
|
-underscores
|
|
Valid Name
|
|
- _myStr
|
|
- my3
|
|
- Hello_there
|
|
Invalid Name
|
|
- 3mt = "hi" -- cannot start with number
|
|
- first name = "hi"
|
|
- first-name
|
def areaOfTriangle(base,height):
area=1/2 * base * height
return(area)
user_base = float(input('Enter the base of the triangle: '))
user_height = float(input('Enter the height of the triangle: '))
#function call
print('The area of the triangle is',areaOfTriangle(user_base,user_height))
def volumeOfPrism(base,height,prism_height):
volume = areaOfTriangle(base,height) * prism_height
return (volume)
user_prism_height = float(input('Enter the prism height:'))
print ('the volume of the prism is', volumeOfPrism(user_base, user_height, user_prism_height))
def isPalindrome(word):
if reverse_item == user_word:
return "true"
else:
return "false"
while True:
user_word = input('What is the word: ')
length = len(user_word)
if user_word == 'quit':
break
else:
print("Length of the word is: ",(length))
reverse = ""
for item in user_word:
reverse = item + reverse
reverse_item = reverse
s = 0
while s < length / 2 + 1 :
if reverse_item[s] == user_word[s]:
print(user_word, "is a palindrome")
break
s = s + 1
else:
print(user_word, "is not a palidrome")
break
|
= =
|
equal to
|
|
!=
|
not equal to
|
|
<
|
less than
|
|
>
|
greater than
|
|
<=
|
less than or equal to
|
|
>=
|
greater than or equal to
|
|
%
|
Modulo, Find the remainder
|
|
String + String
|
combine together
|
|
string + number
|
CRASH
|
|
number + number
|
math
|
|
string * number
|
combine the string
|
|
string * string
|
CRASH
|
|
number * number
|
math
|
|
string ** string
|
CRASH
|
|
number ** number
|
Math
|
|
string ** number
|
CRASH
|
|
Print (2) -interger
|
|
Print (2.4) - Floating Point
|
|
Print (myStr) - variable
|
|
Print ("Hello") - string
|
|
Print (myStr,"Hi",2,1,0) -- commas
|
|
myStr = "Hi"
|
|
mystr - name
|
|
"Hi" - value can change
|
|
print (int(1.5)) - 1
|
|
print (float(1)) - 1.0
|
|
print (4%2) - 0
|
"""
Group member: Kim, Pop, and Earn
Group: 10-03
"""
import random
mylist = ('lion' , 'tiger' , 'dog' , 'bee' , 'cat')
print (mylist)
random_item = random.choice(mylist)
print (random_item)
chance = 7
score = 0
while chance > 0:
user_guess = input("Guess a word: ")
if user_guess == random_item:
score = score + 100
print ("That's Correct!")
print ('score=',(score))
random_item = random.choice(mylist)
else:
if user_guess in mylist:
chance = chance - 1
print ("Sorry, wrong choice")
print ("chance =", (chance))
print ("The word is: ",random_item)
random_item = random.choice(mylist)
print ("score",(score))
else:
chance = chance - 1
print ("Sorry, that is not even in the list")
print ("chance =", (chance))
random_item = random.choice(mylist)
print ("score",(score))
if chance == 0:
print ("GAME OVER!")
print (' Answer =', (random_item))
print ("Final Score =", (score))
def areaOfCircle(r):
pi = 3.1415
area = 2*pi*r
return area
user_radius = float(input("Enter the radius: "))
print("The area of the circle is", areaOfCircle(user_radius))
def calc(num1, num2, operation):
if operation == "sum":
return sum(num1, num2)
elif operation == "product":
return product(num1,num2)
elif operation == "diff":
return diff(num1,num2)
elif operation == "div":
return div(num1,num2)
def sum(a, b):
return (a + b)
def product(a, b):
return (a * b)
def diff(a, b):
return (a - b)
def div(a, b):
return (a / b)
print (calc(1,2,"sum"))
print(calc (4,2, "diff"))
print (calc (9, 3, "div"))
print(calc (2, 12, "product"))
'''
Kim Jaroensattayatham(1003)
'''
def isPalindrome(word):
index = 0
reverse = ""
while int(index) < len(word):
reverse = word[index] + reverse
index = int(index) + 1
if reverse == user_input:
return "true"
else:
return "false"
while True:
user_input = input("please enter the word")
if user_input == "quit":
break
print(len(user_input))
print(isPalindrome(user_input))
import random
intlist = [1,2,3,4,5]
random_int = random.choice(intlist)
print(intlist, random_int)
fplist = [1.0,1.2,1.3]
random_fp = random.choice(fplist)
print(fplist, random_fp)
strlist = ['a','b','c','d','e']
random_str = random.choice(strlist)
print(strlist, random_str)
mylist = [1,1.0,'hello']
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)
'''
theList = ('A' , 'B' , 'C' , 'D')
for item in theList:
print (item)
whileList = ('a' , 'b' , 'c')
index = 0
while index < len(whileList):
print(whileList[index])
index = index + 1
while True:
user_input = input("Enter your word")
print (len(user_input))
if user_input == "exit":
break
def theFunction():
while True:
user_input = input ("Enter the word:")
if user_input == "stop":
break
#call the function
theFunction()
def computeThis(a1,b2):
theproduct = a1 * b2
print(theproduct)
return
computeThis(1,2)
'''
def finalFunction(string):
print("****",string,"****")
return
finalFunction("Kim")
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.