Show Menu
Cheatography

JayJiPm Cheat Sheet by

Function

int()
Change number to be number integer
float()
Change number to be decimal number
str()
A list of number, letter and symbols
print()
Show inform­­ation that you want on the screen
len()
The length of the string
#
Comment, no effect
import random + random.choice
pick random item in the list

Circle area

"""
Python Intro Assignment #2
name
student number
"""

#Ask the user for a radius of a circle
user_radius = input("What is a radius of a circle?")

#Convert the given radius to a floating point
radius = float(user_radius)

#Make a variable called pi
pi = float(3.1415)

#Calculate the area of the circle using exponents
area = pi(radius*2)

#Display the area of the circle to the user
print ("The area of the circle is", area)

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)

Sort word per line

mystr = "Hello"

letter_num = 0

while letter_num < len(mystr):
    print (mystr[letter_num])
    letter_num = letter_num + 1
H
e
l
l
o
 

Addition

string + string
Combine together
string + number
Crash
number + number
Math - addition

Multip­­li­c­ation and Exponents

string * number
Combine that string
string * string
Crash
number * number
Math - multiply
string ** string
Crash
number ** number
Math - exponent
string ** number
Crash

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)
Decimal to Binary
user_n­umber = ' '

while user_n­umber != '0':
user_n­umber = input(­"­Enter a number to convert to binary­")
number = int(fl­oat­(us­er_­num­ber))
binary­_string = ''

while (number > 0):
remainder = number%2
binary­_string = str(re­mai­nder)+ binary­_string
number = number//2

print ("Binary string is",­bin­ary­_st­ring)

Print name

name = "jirat PRASERTMAK"

print (name.upper()) -----------> JIRAT PRASERTMAK
print (name.lower()) -----------> jirat prasertmak
print (name.capitalize()) -----------> Jirat prasertmak
print (name.title()) -----------> Jirat Prasertmak
 

Math

==
equal to
!=
no equal to
<
less than
>
more than
<=
less than or equal
>=
more than or equal
%
Modulo, find the remainder

Vocabulary

variable
Hold a value and can be changed
syntax
Grammar or structure of language
modulo
Find the remainder
boolean
True or false
floating point
The number in decimal

Guess word game

import random

#Create a list

guesslist = ['vesicle', 'lysosome', 'chloroplast', 'ribosome', 'vacuole']

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)

Countdown Machine

user_number = input("What number do you want to count down? ")
number = int(user_name)
countdown-string = ''

while number > 0
    countdown_number = countdown_string + str(number) + " "
    number = number - 1
    #print(number)

print (countdown_string)

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.