• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/13

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

13 Cards in this Set

  • Front
  • Back

How to print to the screen and accept input in python

variableName = input("your text here")




- this will print the text to the screen and wait for a user to press enter (presumably after they have typed their response)




- this will store the response as a String (event tho you don't declare a type anywhere).




- You cannot multiple this String by an number, you will get a TypeError.. again even tho you don't declare types anywhere

How to convert a string into an int

variableName = int(your string variable here)





how to import modules

import moduleName

How to print things to the screen

print("Your string", aVariableIfYouWant, "AnotherStringIfYouWant")

python parses its statements of code by EACH line. thus if you have a statement of code that is too long to fit on 1 line, how to do break it into multiple lines

break them apart with the \ character, then at least 1 space to indent the next line




variableName = math.pi * \


numberVariable + 45




notice the space before numberVariable (must have at least 1 space)

How to make comments in python

# write a comment here

how to declare types in python

there are no primatives in python, everything is an object.




To declare an int, float or string etc.., you pass the value into its constructor which outputs the value so you can store it in a variable




variableNameInt = int(56)


variableNameStr = "heres a string" or 'heres a string'




- strings are declared with either " " or ' '

How to cast a float as an integer

int(float)

what if you divide two integers and the result is a fraction?

Python will convert the result into a float automatically

what if you only wanted the number of times a number divided into another number?

You could cast it like so:


int(4/3)




or you could use the provided operator:




4//3




either way the result is 1




You could return a float version of this if 1 of the number are a float:




4//3.0 = 1.0

How about remainders

Same as java: use modulo %

What about exponent

use two asterisks ** like so:




3**3 = 27

Accumulators and other similar shortcuts

All the same as java




+=


-=


/=


*=