In: Computer Science
In Python
Which statement has a syntax error? Assume variables x, y, z, and age have already been defined.
a. |
y = y |
|
b. |
x + y = z |
|
c. |
age = '32' |
|
d. |
print('Name, age') |
|
e. |
None of the above |
Which statement does not print a newline character at the end?
a. |
print('First part…') |
|
b. |
print('First part…\n') |
|
c. |
print('First part…', end='') |
|
d. |
print('First part…', end=”-\n”) |
|
e. |
None of the above |
Which function converts a string to an integer?
a. |
int() |
|
b. |
integer() |
|
c. |
string_to_int() |
|
d. |
convert(string, int) |
|
e. |
None of the above |
Which statement has a syntax error? Assume variables x, y, z,
and age have already been defined.
a.
y = y
b.
x + y = z
c.
age = '32'
d.
print('Name, age')
e.
None of the above
Answer: b) x+y =z
explanation: as per the syntax rules of python, left side of equals
operator must not be an expression
hence it raises syntax error
Which statement does not print a newline character at the
end?
a.
print('First part…')
b.
print('First part…\n')
c.
print('First part…', end='')
d.
print('First part…', end=”-\n”)
e.
None of the above
Answer:c)print('First part…', end='')
explanation: end ='', it changes end character '\n' to '', so it
will not print a newline
Which function converts a string to an integer?
a.
int()
b.
integer()
c.string_to_int()
d.
convert(string, int)
e.
None of the above
Answer:a)int()
it converts string to integer// if string contains all numeric
characters