Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

GETTING STARTED WITH PYTHON

Unsolved Questions:

3. **Difference between script mode and interactive mode


in Python:**
- Interactive mode: Commands are executed one at a
time, and results are immediately displayed.
- Script mode: Python code is saved in a file (script) and
executed all at once using an interpreter or IDE.

4. **Difference between flow chart and algorithm:**


- Flow chart: A graphical representation of a process or
algorithm using various symbols to depict different steps
and decisions.
- Algorithm: A step-by-step procedure or formula for
solving a problem, often described in natural language or
pseudocode.
5. **Pseudocode to divide two numbers and display the
quotient:**
```
Read number1
Read number2
quotient = number1 / number2
Display quotient
```

6. **Algorithm for coin flipping game to determine


winner:**
```
Initialize player1_wins to 0
Initialize player2_wins to 0

Repeat 5 times:
Read result of coin flip (1 for player 1 win, 2 for player 2
win)
If result == 1:
Increment player1_wins
Else:
Increment player2_wins

If player1_wins == 3:
Display "Player 1 wins the cake"
Exit loop
If player2_wins == 3:
Display "Player 2 wins the cake"
Exit loop
```

7. **Pseudocode to print multiples of 5 between 10 and 25:**


```
For number from 10 to 25:
If number % 5 == 0:
Print number
```

8. **Pseudocode to calculate marks and percentage:**


```
Read marks for Computer Science
Read marks for Mathematics
Read marks for Physics

total_marks = Computer Science + Mathematics + Physics


aggregate_marks = total_marks
percentage = (total_marks / 300) * 100

Display aggregate_marks
Display percentage
```

9. **Algorithm to find the greatest among two different


numbers:**
```
Read number1
Read number2

If number1 > number2:


Display number1
Else:
Display number2
```
10. **Algorithm for conditional statements based on user
input:**
```
Read number

If number >= 5 and number <= 15:


Print "GREEN"
Else if number > 15 and number <= 25:
Print "BLUE"
Else if number > 25 and number <= 35:
Print "ORANGE"
Else:
Print "ALL COLORS ARE BEAUTIFUL"
```

Certainly! Here are the answers to the


next set of questions:
11. **Algorithm to find the largest and smallest of four
numbers:**
```
Read num1
Read num2
Read num3
Read num4

largest = num1
smallest = num1

if num2 > largest:


largest = num2
if num2 < smallest:
smallest = num2

if num3 > largest:


largest = num3
if num3 < smallest:
smallest = num3

if num4 > largest:


largest = num4
if num4 < smallest:
smallest = num4

Display "Largest:", largest


Display "Smallest:", smallest
```

12. **"Decomposition leads to simplicity." How?**


- Decomposition in programming involves breaking down
complex problems into smaller, manageable parts
(functions, modules, etc.).
- This simplifies the overall problem-solving process as
each part can be tackled independently and tested
separately.
- By focusing on smaller units of code, it becomes easier
to understand, maintain, and debug the entire program.

13. **Algorithm to find factorial of an inputted number:**


```
Read n
factorial = 1
For i from 1 to n:
factorial = factorial * i

Display factorial
```

14. **Matching pairs:**


- User: Flow of Control
- Required: Start/Stop of the Process
- Flow chart: Symbol representing a process step
- Symbol: SP (Start/Stop of the Process)
- Functions: Decision-making

15. **Pseudocode to print bill with GST:**


```
Read price
Read quantity

total_cost = price * quantity


gst = total_cost * 0.05
total_bill = total_cost + gst

Display "Total Bill without GST:", total_cost


Display "GST (5%):", gst
Display "Total Bill with GST:", total_bill
```

16. **When was Python released?**


- Python was first released in 1991.

17. **Who developed Python and which two languages


contributed to Python as a programming language?**
- Python was developed by Guido van Rossum.
- Two languages that influenced Python significantly are
ABC and Modula-3.

18. **Is Python case-sensitive?**


- Yes, Python is case-sensitive. Variables `a` and `A` are
treated as different variables.

19. **What is IDLE?**


- IDLE (Integrated Development and Learning
Environment) is Python's default integrated development
environment (IDE). It provides tools for writing, editing,
and running Python code.

20. **Difference between displaying and printing method in


Python:**
- In Python, "printing" typically refers to using the
`print()` function to output text or values to the console.
- "Displaying" generally refers to showing output in a
graphical user interface (GUI) or web interface.

21. **Salient features of Python:**


- Easy-to-read syntax
- Interpreted language with dynamic typing
- Extensive standard library
- Support for multiple programming paradigms
(procedural, object-oriented, functional)
- Cross-platform
- Large community and third-party support

22. **Cross-platform software with respect to Python:**


- Cross-platform software means that it can run on
multiple operating systems without modification.
- Python achieves cross-platform compatibility through
its interpreter and the availability of its runtime
environment (Python Virtual Machine) on various
platforms.

23. **Advantages of Python programming language:**


- Readability and simplicity
- Extensive standard library
- Support for multiple programming paradigms
- Portable and cross-platform
- Dynamically typed with automatic memory
management
- Strong community support and large ecosystem of
libraries and frameworks

Let's address each question one by one:

24. **In how many different ways can you work in Python?
**
- In Python, you can work in several ways:
1. Interactive mode (Python Shell)
2. Script mode (using Python scripts or programs)
3. Integrated Development Environments (IDEs) like
IDLE, PyCharm, etc.
4. Jupyter Notebooks for interactive data analysis and
visualization
5. Command-line execution for quick scripts

25. **Advantages and disadvantages of working in


Interactive mode in Python:**
- **Advantages:**
- Immediate feedback: Allows quick testing and
debugging of small code snippets.
- Educational purposes: Ideal for learning Python syntax
and experimenting with language features.
- Exploration: Useful for exploring modules and libraries
interactively.

- **Disadvantages:**
- Limited for larger programs: Not suitable for
developing complex applications due to lack of file
organization.
- Lack of persistence: Code isn't saved automatically
unless manually copied to a script.
- Hard to reproduce: Difficult to recreate exact
sequences of commands for documentation or sharing.

26. **Instructions in interactive mode:**


- (a) To display sum of 3, 8.0, 6*12:
```
>>> 3 + 8.0 + 6*12
83.0
```

- (b) To print sum of 16, 5.0, 44.0:


```
>>> 16 + 5.0 + 44.0
65.0
```

27. **Instructions in Interactive and Script modes:**


- **Interactive mode:**
```
>>> print("Python is easy to learn and write. It allows us
to work in two modes: Interactive mode and Script mode.
Interactive mode is also known as Python Shell and Script
mode is known as Python Editor. It is a platform-
independent language. We find it interesting to work with
Python.")
Python is easy to learn and write. It allows us to work in
two modes: Interactive mode and Script mode. Interactive
mode is also known as Python Shell and Script mode is
known as Python Editor. It is a platform-independent
language. We find it interesting to work with Python.
```

- **Script mode (create a script file, e.g., `example.py`):**


```python
# example.py
print("Python is easy to learn and write. It allows us to
work in two modes: Interactive mode and Script mode.
Interactive mode is also known as Python Shell and Script
mode is known as Python Editor. It is a platform-
independent language. We find it interesting to work with
Python.")
```
When executed in script mode (`python example.py`), it
would print the same output as in interactive mode.

28. **Code to print full name and birthday as separate


strings:**
```python
# Assuming variables are defined
full_name = "John Doe"
birthday = "January 1, 2000"

print("Full Name:", full_name)


print("Birthday:", birthday)
```

29. **Output of given statements:**


- (a) `print(n=17)`:
- This would raise a `SyntaxError` because `print()`
function does not accept assignment (`n=17`).
- (b) `print(8+9)`:
- Outputs `17`.
- (c) `print(4.2, "hello", 6-2, "world", 15/2.0)`:
- Outputs `4.2 hello 4 world 7.5`.
- (d) `print("123abc", sep='-')`:
- Outputs `123abc`.
- (e) `print("XXX", end='!')`:
- Outputs `XXX!`.

30. **Using IDLE to calculate:**


- (a) `6+4*10`:
```
>>> 6 + 4 * 10
46
```
- (b) `(6+4)*10`:
```
>>> (6 + 4) * 10
100
```

31. **Output evaluation from Python Shell:**


```
>>> print("Python is easy to learn and write.")
Python is easy to learn and write.

>>> print(3.14159 * 7)
21.99113

>>> print('I am a class XI' + 'student')


I am a class XIstudent

>>> print('I', 'm')


Im

>>> print("class XI student")


class XI student

>>> print("I'm ", 16, "years old")


I'm 16 years old
```

You might also like