We are using python in this class
What is rules, syntax, and format when writing a program?
It's when you have to write the program in a specific way in order for the compiler to understand and run the program.
What are comments in programming?
Commented parts of code are ignored by the compiler
What are variables?
You use it to store values and its value can change
What type of variable does the input() command return at default?
string
What is Python?
It's a programming language that is easy to read and use, many ways to use it, and it's very similar to speaking english!
What are new lines used for?
It's used to complete each command you give
How do you write comments? What are comments used for?
You can use comments to explain your code, make your code more readable, and prevent certain parts of your code from being executed. You write one line comments by typing "#" at the start of the comment. You can write more than two line comments by typing """ at the start of the comment and at the end of the comment.
How to define variables?
1. Give it a name
2. Set the variable equal to something
What can numerical operations be used for or help us with?
It can help us compute/calculate things that will take us a long time
What do you have to do in order to test your code?
Click the run button
Can you give an example of format?
Indentation
What is input and output?
Output is printing something on the screen and input is having the user enter information.
What are the three different types of variables that we learned and what can each type of variable store?
Types of variables: int, float, string
int can store numbers with no decimals
float can store numbers with decimals
strings can store text
How do you change the default type variable of the input() method? Can you give an example of code that shows how to do that?
Cast the input() command.
Example:
a = int(input())
b = float(input())
What is an algorithm? How does it relate to computer programming?
It's a set of step-by-step instructions. This related to computer programming because they are both lists of very specific instructions and it's like writing a to-do list for the computer
Can you give an example of syntax?
When putting commands together, you get syntax.
What are two commands you learned so far and give an example of code that uses both of the commands?
Commands: print() and input()
Example:
a = input()
b = input()
print(a+b)
Can you give an example of what you can use variables for?
I can use a variable to store the numbers 10 and 20 in my program, then access them later.
List all eight numerical operations and explain what each operation does. Also explain how to write each numerical operation.
Addition: + used to add numbers and strings
Subtraction: - used to subtract numbers
Multiplication: * used to multiply numbers
Float Division: / used to divide numbers (returns float)
Exponents: ** used the same way as exponents in math
Adding to a variable: += used to add a string or number to a variable
Mod/remainder: % used to get the remainder when dividing numbers
Integer division: // used to divide numbers and rounds value down (returns int)
What can we use programming for?
Web and internet development, desktop GUI's applications, Scientific and Numeric, Software Development, Education, Business Applications, Games and 3D Graphics, Network Programming, and Database Access
What is indentation and how do you write it?
Indentation is what groups together commands in what is called scope. It shows and seperates a block of code. To indent something, press "tab" or space at least once.
What is a command?
Each command has a specific way to write it. These details put together is called syntax
What are the variable naming rules?
1. Can only start with underscore or letter (no starting with numbers!)
2. Case sensitive
3. In the actual name, you can only use letters, numbers and underscores
A plant grows g inches each year and starts off as s inches tall. Write a program that predicts the height of the plant after n years. The values for g, s, and n will be given by the user in that order.
Sample input: Sample output:
4 3 2 11
g is 4, s is 3, and n is 2
g = int(input())
s = int(input())
n = int(input())
inchesGrown = g * n
height = inchesGrown + s
print(height)