Solution for the Python Internal 1
SECTION A
Q1.
Answer: A variable is a named location in the computer's memory used to store data or
values. The value stored in a variable can be accessed and changed during program
execution.
• Advantage: Variables make code reusable and easier to understand. Instead of
repeating a value (like 3.14159) everywhere, you can store it in a well-named variable
(like PI) and use the variable name, which is more readable and easier to change if
needed.
Q2.
(a blank line)
hello
(a blank line)
world
print("") prints an empty string, which results in a blank line. print() with no
arguments also prints just a blank line.
Q3.
• Answer: HELLO@world world@HELLO
• Explanation: The string methods [Link]() and [Link]() return new values; they
do not change the original strings a and b. Since these returned values are not assigned
to any variable, they are lost. The print statement simply prints the original,
unchanged values of a and b.
Q4.
• print(z1) outputs: 10.0
• print(z2) outputs: '10.0' (Note: It's a string)
• print(z3) outputs: (10+0j)
• print(z4) causes a ValueError exception.
• Explanation:
o z1: float() converts the string "10.000" to a floating-point number 10.0.
o z2: str() converts the number 10.000 to its string representation '10.0'.
o z3: complex() converts the number 10.000 to a complex number (10+0j).
o z4: int() expects a string representing a whole number (like "10"). "A" is not a
valid integer literal, so it raises a ValueError.
Q5.
• // is the floor division operator. It divides and returns the largest integer less than or
equal to the result. If either operand is a float, the result is a float.
• / is the true division operator. It always returns a float result, even if the result is a
whole number.
SECTION B (Attempt any 4)
Q6. What is the concept of indentation in Python and why is it important?
• Answer: In Python, indentation (whitespace at the beginning of a line) is not just for
readability; it is syntactically significant. It is used to define blocks of code that
belong to constructs like loops, conditional statements (if, elif, else), and function
definitions.
• Importance: It enforces a clean and consistent coding style, making Python code
highly readable and maintainable. It replaces the curly braces {} used in other
languages like C++ or Java to define code blocks.
Q7. Python is a High Level, dynamically typed and memory efficient language.
Comment.
• Answer: This statement is correct.
o High Level: Python provides strong abstractions from the details of the
computer (like memory management). It uses English-like syntax, making it
easier for humans to read and write compared to low-level languages like
Assembly.
o Dynamically Typed: You don't need to declare the data type of a variable.
The interpreter infers the type at runtime (x = 10 makes x an integer, x =
"hi" later makes it a string).
o Memory Efficient: Python has an efficient built-in memory manager and
garbage collector that automatically handles allocation and deallocation,
freeing the programmer from this task.
Q8. Write a program to take a single digit number from the keyboard and print its
value in English word?
Q9. Write a program that reads a number and prints whether it is positive, negative, or
zero.
Q10. Write a program that takes a single character as input and checks if it is an
alphabet character (either lowercase or uppercase).
SECTION C
Q11. Give the output
name="Vijay@the@boss"
print(name[:1]) # V
print(name[-1::]) # s
print(name[::1]) # Vijay@the@boss
print(name[-1:]) # s
• Explanation:
o name[:1]: Slice from the start (index 0) up to, but not including, index 1. This
is the character at index 0: 'V'.
o name[-1::]: Slice starting from the last character (index -1) to the end, with a
step of 1. This is 's'.
o name[::1]: Slice from the start to the end with a step of 1. This is the entire
string: 'Vijay@the@boss'.
o name[-1:]: Slice from the last character (index -1) to the end. This is 's'.
Q12. Write a program that checks if a number is divisible by both 5 and 11, only 5, only
11, or by neither.