Function
print() |
Show information that you want on the 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 |
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/counting number |
Floating point |
The number in decimal |
Syntax |
Grammar/Structure of lauguage |
Modulo |
Find the remainder |
Boolean |
True/False |
Multiplication 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("Please enter a word")
index = 0
reverse = ' '
while int(index) < len(word):
reverse = word[index] + (reverse)
index = int(index) + 1
print ("Reverse: ", reverse) |
Convert to binary
Convert to binary
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) |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment