Q. Click File --> New File... and type the following code into it:


myNumber = 10
print (myNumber + 1) # output statement 1
print (myNumber) # output statement 2
print (type (myNumber)) # type statement 1
myNumber = 5 + 2
print (myNumber, end = ()) # output statement 3
print (type (myNumber)) # type statement 2
myNumber= "Seven"
print (myNumber) # output statement 4
print (type(myNumber) # type statement 3

Now save your code and run it by pressing F5 key.
Now in the following table fill details as asked as per your observations based on above code:


(a) Output generated by four marked output statements in above code. 1.
2.
3.
4.
(b) Output generated by three marked type statements in above code 1.
2.
3.
(c) Why is the output of output statement 1 different from output statement 2 when we have added 1 to variable Number?
(d) Why is the output of type statement 2 different from type statement 3 when we are displaying output of same variable myNumber?
(e) Assign values 2, 4, 8 to variables a, b and c in single statement.
(f) Swap the values of a, b, c through SINGLE STATEMENT so as they now hold values of c, a, and b respectively.
(g) In a new program there is just one statement given belowprint (value)But it is giving problem upon running the program. Could you tell, why?

Answer =

(a)
1. It will print 11
2. It will print 10
3. It will generate error because end = () that is wrong
4. It will not execute due to error found in previous line code.

(b)
1. <class 'int'>
2. It will not execute due to error found in previous line code.
3. It will not execute due to error found in previous line code.

(c)
In statement 1 there is addition of 1 in print function but value of myNumber will not change. That’s why it will produce different answer.

(d)
Because type statement 2 have integer type value while type statement 3 have string type value.

(e)
a, b, c = 2, 4, 8

(f)
a, b, c = c, a, b

(g)
Because here ‘value’ is variable that is not defined it means ‘value’(variable) have not any value.

14 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post