Unit 2 : Python - Introduction Flashcards
What does user see computer as?
- As a set of tools ( Word Processor, Map )
What can we do as a programmer ? ( 3 )
- Learn the programming languages
- Use tools to build new tools ( VS Code to develop Apps )
- Write tools to automate task
What is a code called when it was executale?
- Program
What should we add at the end of out python file?
- .py ( main.py )
What should we do when naming variables? ( 4 )
- Create a meaningful name ( radius , practice_number )
- Contain letters, numbers and underscore
- Underscore can be used for multi-word variable name ( student_name )
- Use _ when the next was letter ( num1 not num_1 )
What should we not do when naming variable ? ( 2 )
- Cannot begin with a number
- Cannot use the keywords and the reserved words
Is variable name case-sentive?
- Yes ( radius is not the same as Radius )
What is code?
- A set of instructions that reflects human intelligence and problem-solving ability
- Can also be seen as a form of creative expression, especially when attention is given to how users interact with the program ( UX )
What does software allows us to do?
- Package and share this intelligence with others, helping them accomplish tasks without having to solve the underlying problems themselves
What is Interactive?
( Interactive Python )
- Using the interpreter or shell, we can type in commands to get immediate results
What is script?
- Save the code into single file ( .py in python )
What is the difference between interactive vs script ?
- Interactive
- You type directly to Python one line at a time and it responds
- Script
- You enter a sequence of statements (lines) into a file using a text editor and tell Python to
execute the statements in the file
- You enter a sequence of statements (lines) into a file using a text editor and tell Python to
What is constants? What are the valued stored inside constant ?
- Fixed Values
- Numbers, letters and strings
- String constants uses single-quote ( ‘ ) or double-quotes ( “ )
What is a variable ?
- A named place in the memory where a programmer can store data and later retrieve the data using the variable “name”
When should we use assignment operator? What is the symbol of assignment operator?
- When we assign a value to a variable
- =
- It consists an expression on the right hand side and variable name to store the result
List out the symbols in numeric expressions ( 6 )
- ( Called Asterisk )
- /
- ** ( Called Power )
- % ( Called Modulus / Modulas )
What is the noun for the term programming languges must know which expressions to do first?
- Operator Precedence
What are the rules of operator precedence rules ? From top to bottom ( 5 )
- Parenthesis () is always respected
- Exponentation ( Raise to power ** )
- Multiplication, Division and Remainder ( * , / , % )
- Addition and Subtraction ( + , - )
- Left to Right
What is the term concatenate means?
- Put together
What does python variables, literals and constants have?
- Type
- type ‘str’
type ‘int’
How can we know the type in python?
e = “hello”
type(e) # shows type’str’
List out the type of number
- Integers
- Floating Points
What will happen when we put an integer and floating together? ( What type will get )
- Float
How can we change the type if available?
e = 1
e = str(e) # Use this code to change from int to str
- It will contain error when the string does not contain numeris characters
What does the input function returns?
- String
How can we input value from python?
name = input(“Please enter your name : “)
print(name)
- When converting the str input to int
age = int(input(“Age : ”))
List out the 2 types of comments
- Single-line comment ( # )
- Multiline comment ( “”” - Start and End )
Why should we use comments? ( 3 )
- Describe what is going to happen in a sequence of code
- Document who wrote the code or other ancillary information
- Turn off a line of code ( perhaps temporarily )
What is program steps ( program flow ) like ?
- Like a recipe or installation instructions, a program is a sequence of
steps to be done in order
What are the steps? ( 3 )
- Some steps are conditional - they may be skipped
- Sometimes a step or group of steps are to be repeated
- Sometimes we store a set of steps to be used over and over as needed in several places throughout the program