BasicCode
print() |
write word on python |
print("Hello There") |
input() |
let people input their information in python |
input("insert number") |
len() |
show the length of that word |
len(word) |
int() |
Number into number integer |
int(2.50) |
float() |
Change number into decimal |
float(5) |
str() |
a list of number and letter |
str(10) |
# |
It's comment |
print("Hello There")#It prints Hello There |
Make a list
shoppinglist = ['bags', 'shoes', 'boots', 'shirts'] |
|
print (shoppinglist[2]) |
|
item_number = 0 |
|
""" |
while item_number < len(shoppinglist): |
print ("List item:",shoppinglist[item_number]) |
item_number = item_number + 1 |
""" |
|
|
out = 0 |
for muids in shoppinglist: |
out = out + 1 |
|
print(out) |
|
Result = |
boots |
4 |
Calculate Math
string +\-*\/ string |
calculate string |
number +\-*\/ number |
calculate number |
number +\-\/ string |
CANT |
string +\-\/ number |
CANT |
string * number |
It will multiply amount of string ex: str(5) * 6 = 555555 |
number * string |
It will multiply amount of string ex: 6 * str(5X = 555555 |
number ** number |
Exponent |
number ** string |
CANT |
|
|
Math Code For python
== |
equal |
3 == 3 |
!= |
not equal |
4 != 3 |
< |
less than |
3 < 4 |
> |
more than |
4 > 3 |
<= |
less than or equal |
len(word) <= letternum |
>= |
more than or equal |
len(word) >= letternum |
% |
find the remainder |
5%4 |
isPalindrome
def isPalindrome(word):
reverse = ""
for item in word:
reverse = item + reverse
if reverse == word:
return True
else:
return False
while True:
word = input("Insert Word Plz: ")
length = len(word)
if word == "quit":
break
else:
print (length)
lengthnum = 0
while lengthnum < length / 2 + 1:
if word[lengthnum] != word[-lengthnum-1]:
print ("It is not palindrome")
break
lengthnum += 1
else:
print ("It is palindrome") |
find largest value
def max2(num1, num2):
if num1>num2:
return (num1)
if num2>num1:
return (num2)
def max3(num1, num2, num3):
if num1 > num3 and num1 > num2:
return (num1)
if num2 > num1 and num2 > num3:
return (num2)
if num3 > num1 and num3 > num2:
return (num3)
num1 = input("Insert num1")
num2 = input("Insert num2")
num3 = input("Insert num3")
print("the largest number", max3(num1, num2, num3)) |
areaOfEllipse
def areaOfEllipse(rad1,rad2):
print (3.14rad1rad2)
rad1 = int(input("r1="))
rad2 = int(input("r2="))
areaOfEllipse(rad1,rad2) |
|
|
Basic Vocabulary
Variable |
a value and can ne change |
String |
a list of character such as number and letter |
Integer Number |
whole number |
Floating Point |
decimal number |
Syntax |
Grammar |
Modulo |
Find remainder |
Boolean |
True/False |
Reverse Code
word = input("insert a word plz") Ex:phon
reverse =""
letter_num = 0
while letter_num < len(word):
reverse = word[letter_num] + reverse
letter_num = letter_num + 1
print ("Reverse: ",reverse)
Result = nohp |
Loop List
mylist = [1,2,3,4,5,6]
mylist2 = ['a', 'b', 'c']
mylist3 = [1, 'b', 2.5]
print (mylist)
print (mylist2)
print (mylist3)
mynumbers = range(11)
for num in mynumbers:
print (num)
mylist2.append('another item')
print (mylist2) |
Random: PYthon
import random
mylist = ['Red', 'Green', 'Blue', 'Yellow', 'Purple', 'Black']
print (mylist)
user_guess = input("Guess a word: ")
random_item = random.choice(mylist)
print (random_item)
if user_guess == random_item:
print("Correct Guess")
else:
if user_guess in mylist:
print ("Yes, in the list")
else:
print ("No, not in the list") |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
More Cheat Sheets by phon