ANSWERS VERIFIED 100% CORRECT|
GRADED A +|
What must be true to convert from a string to an integer or float? - ANSWER There must be a
"clearly" defined conversion.
Examples:
int('3') has the integer value of 3 float('3.14')
has the float value of 3.14 float('2') has the
float value of 2.0
int('2.5') has an ERROR since it cannot convert to a float and then to an int all in one step
x = str(1/2)
print(x)
What would be the output of the previous? - ANSWER 0.5
Note: 0.5 would be a string and the operation of 1/2 is done before the conversion to a string
x = str(10*1.0) print(x)
What would be the output of the previous and what is the type of x? - ANSWER 10.0 Type
of x: string
How to convert from and to a boolean value? - ANSWER Using the bool() function
x=1
bool(x)
When you convert FROM a boolean value what are True and False values assumed to be? -
ANSWER True is assumed to have the value 1
False is assumed to have the value 0
, When you convert TO a boolean value what numeric is False? - ANSWER The numeric value 0
has the value False and ANYTHING ElSE has the value True
What value does x store in the following code?
x = int(True) - ANSWER 1
What value does x store in the following code?
x = float(True) - ANSWER 1.0
What value does x store in the following code?
x = float(False) - ANSWER 0.0
What value does x store in the following code?
x = bool(0) - ANSWER False
What value does x store in the following code?
x = bool(3) - ANSWER True
What value does x store in the following code?
x = bool('0') - ANSWER True
Note: It is a string input within the bool function, NOT the numeric number 0
What value does x store in the following code?
x = bool('') - ANSWER False
Note: The empty string = 0
What value does x store in the following code?
x = bool('False') - ANSWER True Note: 'False'
Is NOT the numeric 0
How do you print more than one value or variable within the print statmenet? - ANSWER
Separate them by commas
Ex:
, print(2.0, 'is', 2)
Output:
2.0 is 2
What is the output of the following?
x=3
y=4
print(x, ':', y) - ANSWER 3 : 4
What is the output of the following?
x=3
y=4
print(str(x) + ':' + str(y)) - ANSWER 3:4
What is the value of the following?
"2.3".ljust(10) - ANSWER '2.3 ________'
What is the value of the following?
"2.3".rjust(10) - ANSWER '________2.3'
What is the value of the following?
"2.3".center(10) - ANSWER ' ____2.3____ '
How do you change how things are separated in the print statement? - ANSWER print(...,
sep="<something>")
How do you change what is done after printing? - ANSWER print(....,end="<something>")
What is the output of the following print statements?
print("Test", 3, 5, sep=',', end=':')
print(15) - ANSWER Test,3,5:15
How do you use the format() function in python? - ANSWER <string>.format(<values>)