|
print()
|
displays information that you want to show on the screen
|
|
int()
|
Change number to be number integer
|
|
input()
|
Gain information from user
|
|
str()
|
A list of number, letter and symbols
|
|
len()
|
The length of the string
|
|
#
|
Comment, no effect
|
|
string * string
|
Crash!
|
|
string * number
|
combine that string
|
|
number * number
|
multiply (Math)
|
|
string ** string
|
Crash!
|
|
number ** number
|
Exponent(Math)
|
|
string ** number
|
Crash!
|
user_number = input("What number do you want to countdown?")
number = int(user_number)
countdown_String = ' '
while number > 0:
countdown_number = countdown_string + str(number) + ""
number = number + 1
#print number
print (countdown_string)
while True:
user_input = int(input("what is your number:"))
integer = user_input*10
print (integer)
if 3 < 2: #if statement must compare 2 booleans
print ('3 is less than 2')
elif 4 < 2: #can have 0 or more elif statements.
print ('4 is less than 2')
elif 5 < 2:
print ('5 is less than 2')
else: #can have 0 or 1 else statement at the end
print ('none of above are true')
|
variable
|
something that can be change
|
|
string
|
a list of characters such as number,letter and symbols
|
|
Integer number
|
Whole number/counting number
|
|
Float number
|
The number in decimal
|
|
Syntax
|
Grammar/Structure of language
|
|
Modulo
|
Find the remainder
|
|
Boolean
|
True/False
|
|
string + string
|
combine number
|
|
string +number
|
CRASH!
|
|
number + number
|
Addition (Math)
|
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):
if b!=0:
return (a//b)
else:
print ("error")
print (calc(10, 0, "div"))
print(calc(1,2,"sum"))
print(calc(4,2,"diff"))
print(calc(9,3,"div"))
print(calc(2,12,"product"))
forlist = ['hi', 'hello', 'goodbye']
for gg in forlist:
print(gg)
|
==
|
equal to
|
|
!=
|
no equal to
|
|
<
|
less than
|
|
>
|
more than
|
|
<=
|
less than or equal to
|
|
>=
|
more than or equal to
|
|
%
|
Modulo, Give remainder when dividing
|
|
and
|
|
|
or
|
|
|
not
|
|
|
*
|
multiply
|
|
/
|
divide with answer as a float 5/2 = 2.5
|
|
//
|
divide with answer as an interger 5//2 = 2
|
|
**
|
exponent 2**3 = 8
|
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)
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)
import random
intlist = [1, 2, 3, 4, 5]
random_int = random.choice(intlist)
print(intlist, random_int)
fplist = [1.1, 1.2, 1.3, 1.4]
random_fp = random.choice(fplist)
print (fplist, random_fp)
strlist = ["Allo", "Stego", "Carno", "T-rex"]
random_str = random.choice(strlist)
print(strlist, random_str)
mylist = ["Yasashii", 1.3, 2]
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)
wlist = [2, 4, 5, 6, 7, 8]
gg = 0
while gg < len(wlist):
print (wlist[gg])
gg = gg + 1
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.