In Python quotation marks are used to wrap strings.
True/False
True
What are variables?
A function is an encased block of code that only runs when the function's name is called. It is a reusable block of programming statements designed to perform a certain task.
What is the error in the code below?
number=int(input("Enter a number:"))
x=4*number
print(number)
There is no error, hehe>:)
While quotation marks are not used for integers, they are used for floats.
True/False
FALSE!! Both do not use quotation marks, only strings use quotation marks.
What is a while loop and when is it used?
A while loop is used to execute a set of statements when the function is true. If the function is processed as false, then the loop stops. Variables need to be defined in the lines above the loop for the while loop to function!
Find the problem in the code below:
name=input("Enter name:")
hobby=int(intput("How many hobbies do you have(enter a number):"))
1answeR!= hobby-hobby
print(name,"has",1answeR!,"hobbies.")
A variable cannot start with a number.
You have to use if/else statements only for calculations and if there is less than 4 conditions.
True/False
False
If/Else statements are used when there are two or more answers displayed after a conditional statement.
Define a for loop and what differentiates it from a while loop.
A for loop is used when you want to iterate a sequence, such as a list, a fixed number of times. Within the parenthesis, you input the range, or the number of times you wish for the loop to repeat. While a while loop continues infinity unless the function is false.
What is the error in the code below
animal = input("Enter an animal: ")
sound = input("Enter a sound: ")
e = " E-I-E-I-O"
print("Old Macdonald had a farm," + e)
print("And on his farm he had a", animal + "," + e)
print("With a " + sound + "-" + sound + " here and a " + sound + "-" + sound, 'there")
print("I showed my mercy by not writing the rest of the song", e)
On the third print statement the string "there" had mismatched quotation marks: 'there". Correct way to write it would be "there"
To multiply two numbers you use two * (ex: 8**7)
To raise the first number to the power of the second number you only use one *(ex:9*6)
True/False
False!!
Its the other way around. To multiply you use one * and for exponents you use two *
What does the modulus do?
% finds the remainder from division
What is the error in the code below:(only 2 minutes)
A=int(input("Enter side A:"))
B=int(input("Enter side B:"))
C=int(input("Enter side C:"))
D=int(input('Enter side D:"))
E=int(input("Enter side E:"))
Dside=(D-E)
Fside=(A-C)
area1=Fside*Dside
area2=C*B
area3=0.5*E*Fslde
sum_Area=area1+area2+area3
print("Room Area:", sumArea)
There were 3 problems in the code
1- D had mismatching quotation marks
2- in the print statement the variable sumArea is undefined.
3- when the variable in the print statement is spelled correctly–sum_Area– it needs the str() function.