3.1 and 3.2 Notes and Hacks
These are my 3.1 and 3.2 Notes and Hacks
# Variable has a value of "Alex"
x = "Alex"
print(x)
name = "Timmy"
age = "25"
print(name + " is " + age)
age = "18"
name = "Shruthi"
print(name + " is " + age)
Hacks 2
The assignment operator is the transition character of a variable. A variable is an abstraction made inside a program that holds a value. College board uses assignment operator <- In python, the assignment operator is an equal sign. A variable, x, is initially given a value of 15. Later on, the value for x is changed to 22. If you print x, the command would display 22.
Hacks 3
A list is a sequence of elements with each element being a variable. An easy way to reference the elements is in a list. Example of a string: "hello world"
songList = ["american pie", "country roads", "annie's song", "ladies love country boys"]
print(songList[2])
print(songList[-1])
foodList = ["caulifour", "pizza", "egg curry", "circle-shaped eggplant"]
print(foodList[0])
print(foodList[-1])
<html>
<body>
<div class="container">
<div class="calendar">
<div class="month">
<button id="prev" onclick="prev()">Prev</button>
<button id="next" onclick="next()">Next</button>
<p id="month">Month Here</p>
</div>
</div>
</div>
<script>
let months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
let index = 0;
function next() {
if (index > 11) {
index = 0;
}
else {
index += 1;
}
document.getElementById("month").innerHTML = months[index]
}
function prev() {
if (index < 0) {
index = 11;
}
else {
index -= 1;
}
document.getElementById("month").innerHTML = months[index]
}
document.getElementById("month").innerHTML = months[index]
</script>
</body>
</html>
num1=input("Input a number. ")
num2=input("Input a number. ")
num3=input("Input a number. ")
add=input("How much would you like to add? ")
# Add code in the space below
numlist = [int(num1), int(num2), int(num3)]
print("Original numbers:",numlist)
print("Adding:",add)
for i in range(len(numlist)):
numlist[i -1] += int(add)
print(numlist)
food1 = "cauliflour"
food2 = "pizza"
food3 = "egg curry"
food4 = "circle-shaped eggplant"
print(food1, food2, food3, food4)
scores = [95, 84, 85, 99]
print(scores)