0% found this document useful (0 votes)
2 views2 pages

Python Answers

The document outlines various programming concepts including why slicing and concatenation do not apply to dictionaries, algorithms for calculating the perimeter of a rectangle, and functions for printing multiplication tables. It also discusses error types in Python, the nature of digital footprints, and properties of dictionary keys. Additionally, it contrasts lists and dictionaries, and explains the behavior of loops and leap year checks.

Uploaded by

kumarsujit70317
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Python Answers

The document outlines various programming concepts including why slicing and concatenation do not apply to dictionaries, algorithms for calculating the perimeter of a rectangle, and functions for printing multiplication tables. It also discusses error types in Python, the nature of digital footprints, and properties of dictionary keys. Additionally, it contrasts lists and dictionaries, and explains the behavior of loops and leap year checks.

Uploaded by

kumarsujit70317
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. Why slicing and concatenation cannot be applied to a dictionary?

• Dictionary elements are accessed using keys, not index positions.


• Slicing works only with sequence data types like list, tuple, and string.
• Concatenation is not supported because dictionaries store key-value pairs.

2. Algorithm to find the perimeter of a rectangle

• Start
• Read length and breadth
• Calculate perimeter = 2 × (length + breadth)
• Display perimeter
• Stop

3. Function to print the table of a given number

• Accept a number from the user


• Use a loop from 1 to 10
• Multiply number with loop variable
• Print the result

4. Program to find minimum and maximum of five numbers

• Accept five numbers from the user


• Store them in a list
• Use min() to find minimum
• Use max() to find maximum
• Display results

5. Program to check leap year

• Accept year from user


• If year divisible by 400 → leap year
• Else if divisible by 100 → not leap year
• Else if divisible by 4 → leap year
• Else → not leap year

6. What happens when break is encountered?

• It immediately terminates the loop


• Control comes out of the loop
• Execution continues with next statement after loop

7. Literals in Python

• Literals are fixed values assigned to variables


• Examples: numeric, string, boolean, special literals
• They represent constant values in a program

8. Syntax error and logical error

• Syntax error: Occurs due to wrong grammar of code


• Logical error: Program runs but gives wrong output
• Syntax errors are detected by interpreter

9. Digital footprints

• Digital footprints are traces left by users online


• Active: Data shared intentionally (posts, comments)
• Passive: Data collected automatically (cookies, IP address)
10. While loop

• While loop executes as long as condition is true


• Condition is checked before execution
• Used when number of iterations is unknown

11. Dictionary keys – any three properties

• Keys must be unique


• Keys must be immutable
• Keys are case-sensitive

12. Difference between list and dictionary

• List stores elements in order, dictionary stores key-value pairs


• List uses index, dictionary uses keys
• List allows duplicates, dictionary keys do not

You might also like