Python Questions - Set 2 Flashcards
What is the output of
~~~
2 ** 3
~~~
2 raised to power 3
8
What is the output of ,
~~~
x = 10 / 4
y = 5 / 2.0
print (x + y)
~~~
5.0
What is the output of,
~~~
x = 13 / 4
y = 13 % 4
print(x + y )
~~~
x = 3.25 y = 1 x + y = 4.25
What is the output of,
~~~
6. // 4
~~~
1.0
What is the output of the following python code if we enter 5 as input?
~~~
Num = input(“Enter a Number: “)
print (Num * 3 )
~~~
555
Which method should you use in order to convert the input into a string correctly:
~~~
year_of_birth = int(input(“In what year were you born? “))
print(“You were born in “ + …(year_of_birth))
~~~
str
What is the output of the following Python code,
~~~
x = 5
y = “Sally”
print(str(x) + y)
~~~
5Sally
What is the output of the following python code if we enter “HelloPython” as input,
~~~
inputString = input(‘Enter a string: ‘)
print(inputString*2)
~~~
HelloPythonHelloPython
What is the output of the following python code if we enter 5 as input
~~~
Num = input(“Enter a Number: “)
Num = int(Num)
print ( Num * 3 )
~~~
15
What is the output of the following python code,
~~~
print(‘My age is ‘ + 25)
~~~
It gives anTypeError
What is the output of this Python code,
~~~
print(int(“Hello”))
~~~
It gives an invalid literal error
It means, only numbers as strings can be type casted to integer
~~~
print(int(‘5’))
~~~
is correct
What is the output of,
~~~
print(a)
~~~
name ‘a’ is not defined
What is the output of,
~~~
print(“Ha” -1)
~~~
It gives an error,
unsupported operand type for - : str & int
How to print value of character
We have to use ord() method
~~~
c = ‘g’
print(ord(c))
~~~
if we have a variable ,
~~~
c = ‘g’
~~~
then how print this output without fstring
“The ASCII value of ‘g’ is 103 “
~~~
c = ‘g’
print(“The ASCII value of ‘” + c + “’ is”, ord(c)
```)