|
Variable
|
Something that can be changed
|
|
Module
|
File containing Python definitions and statements
|
|
String
|
A list of characters in order
|
|
Print
|
Show the information on the screen
|
|
Input
|
The information from the user
|
|
Syntax
|
Spelling and grammar of language
|
|
Integer number
|
Whole number or counting number
|
|
Syntax error
|
An error in a program that makes it impossible to parse
|
|
Len
|
Return the length of an object
|
|
Integer number
|
Whole number or counting number
|
|
Float number
|
The number in decimal
|
name = "kaewkawee PLEUMCHAROEN"
print (name.upper()) -----------> KAEWKAWEE PLEUMCHAROEN
print (name.lower()) -----------> kaewkawee pleumcharoen
print (name.capitalize()) -----------> Kaewkawee pleumcharoen
print (name.title()) -----------> Kaewkawee Pleumcharoen
mylists3 =[1, 'hello' , 2.5]
print (mylists)
print (mylists2)
print (mylists3)
#how to make a list with all numbers from 0-99
mynumbers = range(5)
for num in numbers:
print(num)
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)
|
!=
|
Not equal to
|
|
==
|
Equal to
|
|
<
|
Less than
|
|
>
|
More than
|
|
<=
|
Less than or equal to
|
|
>=
|
More than or equal to
|
|
%
|
Modulo, Find the remainder
|
|
print()
|
show information on the screen
|
|
float()
|
Change number to be decimal number
|
|
str()
|
converts
|
|
len()
|
the length of the string
|
|
#
|
comment
|
|
input()
|
receives information from the user
|
|
import random + random.choice(list)
|
pick random item from the list
|
|
int()
|
change number to be number integer
|
import random
mylist = ["Dog", "Fish", "Cat", "Bear"]
counter = 0
while counter < 10 :
random_item = random.choice (mylist)
print (random_item)
counter = counter + 1
|
string*string
|
crash
|
|
string*number
|
combines he string multiple times
|
|
number*number
|
math-multiply
|
|
string**number
|
crash
|
|
string+string
|
combines the string together
|
|
string+number
|
crash
|
|
number+number
|
Math - addition
|
user_number = ' '
while user_number != '0' ;
user_name = 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:
user_radius = input("What is the radius?")
radius = float(user_radius)
pi = 3.1415
area= pi radius * 2
print ("The area of the circle is", area)
import random
#Create a list
guesslist = ['grape', 'orange', 'chloroplast', 'ribosome', 'lipstick']
chance = 3
score = 0
print (guesslist)
while chance != 0:
random_item = random.choice(guesslist)
user_input = input("Please guess a word: ")
if user_input == random_item:
print ("That's correct!")
score = score + 100
print ("Score:", score)
else:
if user_input not in guesslist:
print ("Sorry, that isn't even in the list!")
chance = chance - 1
print ("Chance Remaining:", chance)
else:
print ("Sorry, wrong choice!")
chance = chance - 1
print ("Chance Remaining:", chance)
if chance == 0:
print ("The word was", random_item)
print ("The score is", score)
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.