Podcast
Questions and Answers
What will the types of the variables x, y and z be after executing the following code, assuming the user enters 6?
x = input("Enter a number: ")
y = int(x)
z = y / 2
What will the types of the variables x, y and z be after executing the following code, assuming the user enters 6?
x = input("Enter a number: ") y = int(x) z = y / 2
- x - int, y - int, z - int
- x - str, y - int, z - float (correct)
- x - int, y - int, z - float
- types different from the other answers
- x - str, y - int, z - int
Which of the following statements is FALSE about while loops?
Which of the following statements is FALSE about while loops?
- Any while loop can be rewritten as an equivalent for loop. (correct)
- Some while loops can loop forever.
- Any while loop containing a break statement can be rewritten as an equivalent while loop without a break statement.
- Some while loops can exit without their body being executed at all.
- Any for loop can be written as an equivalent while loop.
What will happen if we make the call years_to_become_millionaire(0)
to the following function?
def years_to_become_millionaire(amount):
interest_rate = 0.055
year = 0
while amount < 1000000:
amount = amount * (1 + interest_rate)
year = year + 1
return year
What will happen if we make the call years_to_become_millionaire(0)
to the following function?
def years_to_become_millionaire(amount): interest_rate = 0.055 year = 0 while amount < 1000000: amount = amount * (1 + interest_rate) year = year + 1 return year
- The while loop will never exit and the function will return 0.
- The function will give an error.
- The while loop will never exit and the function will return Infinity. (correct)
- The while loop will loop forever and the function will never return anything.
- The while loop will exit straight away and the function will return 0.
Flashcards
string
string
A sequence of characters, often used to represent text or data.
integer
integer
A data type typically representing whole numbers without a fractional part.
float
float
A data type that can represent numbers with decimal parts.
input() function
input() function
Signup and view all the flashcards
int() function
int() function
Signup and view all the flashcards
while loop
while loop
Signup and view all the flashcards
while loop condition
while loop condition
Signup and view all the flashcards
break statement
break statement
Signup and view all the flashcards
for loop
for loop
Signup and view all the flashcards
infinite loop
infinite loop
Signup and view all the flashcards
continue statement
continue statement
Signup and view all the flashcards
function
function
Signup and view all the flashcards
return value
return value
Signup and view all the flashcards
function call
function call
Signup and view all the flashcards
parameter
parameter
Signup and view all the flashcards
exponent
exponent
Signup and view all the flashcards
compound interest
compound interest
Signup and view all the flashcards
interest rate
interest rate
Signup and view all the flashcards
amount
amount
Signup and view all the flashcards
year
year
Signup and view all the flashcards
counter variable
counter variable
Signup and view all the flashcards
loop condition
loop condition
Signup and view all the flashcards
Study Notes
Question 1 Summary
- The variable x is assigned input from the user
- Variable y is assigned to the integer value of x
- Variable z is assigned to the integer value of y divided by 2
- The type of x will be string (str) because it is initially assigned string input
- The type of y will be integer (int) because int(x) convert x to an integer
- The type of z will be integer (int) as the result of y divided by a integer is an integer
- The correct answer is x - str, y - int, z - int
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.