0% found this document useful (0 votes)
8 views14 pages

? Python (Sec-1)

The document provides a comprehensive overview of Python and Gnuplot for mathematical physics practicals, covering basic concepts, data types, control statements, functions, and libraries like NumPy for numerical calculations. It includes important commands for data plotting and curve fitting using Gnuplot, along with key differences between Python and Gnuplot. Additionally, it lists common viva questions and answers related to these tools, emphasizing their applications in physics.
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)
8 views14 pages

? Python (Sec-1)

The document provides a comprehensive overview of Python and Gnuplot for mathematical physics practicals, covering basic concepts, data types, control statements, functions, and libraries like NumPy for numerical calculations. It includes important commands for data plotting and curve fitting using Gnuplot, along with key differences between Python and Gnuplot. Additionally, it lists common viva questions and answers related to these tools, emphasizing their applications in physics.
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

MATHEMATICAL PHYSICS PRACTICAL (SEC -1)

🐍 PYTHON – Viva Answers


🔹 Basic Concepts
1. What is Python?
Python is a high-level, interpreted programming language used for scientific computing,
data analysis, and plotting in physics.

2. Why is Python used in physics?


Because it is:

 Easy to learn
 Has libraries like NumPy & Matplotlib
 Useful for calculations, simulations, and graphs

3. Compiled vs Interpreted language

 Compiled (C): converted to machine code before execution


 Interpreted (Python): executed line-by-line

4. What are variables and data types?

 Variable: stores value


 Data type: type of value (int, float, etc.)

5. Dynamic typing
No need to declare type; Python assigns automatically.

🔹 Data Types
6. int, float, complex

 int → integer (5)


 float → decimal (5.2)
 complex → (2+3j)

7. List, Tuple, Set, Dictionary

 List → mutable
 Tuple → immutable
 Set → unique values
 Dictionary → key-value pairs
MATHEMATICAL PHYSICS PRACTICAL (SEC -1)

🔹 Input/Output
8. input() vs print()

 input() → takes input


 print() → shows output

9. Why float(input())?
Because input is string by default; we convert to number.

🔹 Operators
10. Types of operators
Arithmetic, relational, logical, assignment

11. / vs //

 / → float division
 // → integer division

12. = vs ==

 = → assignment
 == → comparison

🔹 Control Statements
13. if, elif, else
Used for decision making

14. Loop
Repeats a block of code

15. for vs while

 for → fixed iteration


 while → condition-based

16. break & continue

 break → stops loop


 continue → skips iteration
MATHEMATICAL PHYSICS PRACTICAL (SEC -1)

🔹 Functions
17. Function
Block of reusable code

18. Built-in vs User-defined

 Built-in → already present


 User-defined → created by user

19. Return value


Value sent back by function

🔹 Lists & Indexing


20. List
Ordered collection of elements

21. List vs Tuple

 List → changeable
 Tuple → fixed

22. Indexing & slicing

 Indexing → access element


 Slicing → access range

🔹 NumPy (VERY IMPORTANT)


23. What is NumPy?
A library for numerical calculations

24. Why faster than list?


Uses optimized C code and arrays

25. Array
Collection of same-type elements

26. List vs NumPy array

 List → slower, mixed types


MATHEMATICAL PHYSICS PRACTICAL (SEC -1)

 Array → faster, same type

27. Functions

 linspace() → equal intervals


 arange() → range with step
 zeros() → array of zeros
 ones() → array of ones
MATHEMATICAL PHYSICS PRACTICAL (SEC -1)

📊 GNUPLOT – Viva Answers


🔹 Basics
1. What is Gnuplot?
A command-line tool used to plot graphs and analyze data.

2. Why used in physics?


To plot experimental data and perform curve fitting.

🔹 Commands
3. Basic plot command

plot "[Link]" using 1:2

4. using 1:2
Column 1 → x-axis
Column 2 → y-axis

5. Multiple graphs

plot "[Link]" using 1:2, "[Link]" using 1:2

🔹 Graph Features
6. Title, labels, grid

set title "Graph"


set xlabel "X"
set ylabel "Y"
set grid

🔹 Curve Fitting (VERY IMPORTANT)


7. Curve fitting
Process of finding best-fit curve for data

8. fit command

fit f(x) "[Link]" using 1:2 via a,b

9. Plot vs Fit
MATHEMATICAL PHYSICS PRACTICAL (SEC -1)

 Plot → just graph


 Fit → finds equation

🔹 Data Handling
10. Data file
File containing experimental values

11. Arrangement
Columns (x, y, …)

🔹 Output
12. Save graph

set terminal png


set output "[Link]"
MATHEMATICAL PHYSICS PRACTICAL (SEC -1)

🔥 MOST IMPORTANT FINAL VIVA


ANSWERS
Why Python over C?
Python is easier and has scientific libraries.

Python vs Gnuplot

 Python → programming + plotting


 Gnuplot → only plotting

Curve fitting importance


Helps find relation between variables.

Plot experimental data


Using Python (Matplotlib) or Gnuplot.

Error in graph
Difference between experimental and true value.
MATHEMATICAL PHYSICS PRACTICAL (SEC -1)

🐍📊 TOP 20 VIVA QUESTIONS (WITH


SHORT ANSWERS)
🔥 VERY HIGH PROBABILITY (Must Prepare)
1. What is Python?
A high-level, interpreted language used for calculations and plotting.

2. Why is Python used in physics?


Because it is simple and has libraries for numerical analysis and graphs.

3. What is NumPy?
A library used for fast numerical computations with arrays.

4. Why is NumPy faster than lists?


Because it uses optimized C-based arrays.

5. What is Matplotlib?
A library used to plot graphs in Python.

6. Difference between plot() and scatter()

 plot() → line graph


 scatter() → data points

7. What is a loop?
A structure that repeats a block of code.

8. Difference between for and while loop

 for → fixed iterations


 while → condition-based
MATHEMATICAL PHYSICS PRACTICAL (SEC -1)

9. Difference between = and ==

 = → assignment
 == → comparison

10. What is type conversion?


Changing one data type into another (e.g., string to float).

📊 GNUPLOT IMPORTANT
11. What is Gnuplot?
A command-line tool used to plot graphs and fit data.

12. Basic plotting command

plot "[Link]" using 1:2

13. What does using 1:2 mean?


Column 1 is x-axis, column 2 is y-axis.

14. What is curve fitting?


Finding the best mathematical equation for data.

15. Difference between plot and fit

 plot → only graph


 fit → finds equation

⚡ MIXED / CONCEPTUAL (Examiners Love These)


16. Python vs Gnuplot

 Python → programming + plotting


MATHEMATICAL PHYSICS PRACTICAL (SEC -1)

 Gnuplot → only plotting

17. What is an array?


Collection of same-type elements stored together.

18. What is slicing?


Accessing a part of a list or array.

19. What is error in graph?


Difference between measured and actual value.

20. How do you save a graph?

Python:

[Link]("[Link]")

Gnuplot:

set terminal png


set output "[Link]"
MATHEMATICAL PHYSICS PRACTICAL (SEC -1)

🐍 PYTHON – EXACT VIVA ANSWERS


🔹 From Your Program (MOST IMPORTANT)
1. Explain your program line by line
“This program takes input data, processes it using NumPy, and plots a graph using
Matplotlib. First, libraries are imported, then data is defined, then calculation is done, and
finally graph is plotted.”

2. Why did you use NumPy / Matplotlib?


“NumPy is used for fast numerical calculations, and Matplotlib is used for plotting graphs.”

3. What happens if input changes?


“The output will change accordingly because the program recalculates based on new input.”

4. What is the output of your code?


“It produces numerical results and a graphical representation of the data.”

5. Can you modify the program?


“Yes, for example I can change input values, graph type, or add labels and title.”

🔹 Basic Python
6. What is Python?
Python is a high-level interpreted programming language used for scientific computing.

7. Why is Python interpreted?


Because code is executed line-by-line without separate compilation.
MATHEMATICAL PHYSICS PRACTICAL (SEC -1)

8. What are data types?


They define the type of data stored, like int, float, list, etc.

9. List vs Tuple

 List → mutable (can change)


 Tuple → immutable (cannot change)

10. What is indentation?


Indentation defines blocks of code in Python.

🔹 Logic / Concepts
11. for vs while loop

 for → fixed number of iterations


 while → runs until condition is false

12. What is a function?


A reusable block of code that performs a task.

13. What is slicing?


Accessing a part of a list or array.

14. What is type conversion?


Changing data type, e.g. string to float.

15. What is NumPy array?


An array of same-type elements used for fast calculations.
MATHEMATICAL PHYSICS PRACTICAL (SEC -1)

📊 GNUPLOT – EXACT VIVA ANSWERS


🔹 Basics
16. What is Gnuplot?
It is a command-line software used to plot graphs and analyze data.

17. What does using 1:2 mean?


Column 1 is taken as x-axis and column 2 as y-axis.

18. How to plot a graph from data file?


Using:

plot "[Link]" using 1:2

19. What is curve fitting?


It is the process of finding the best-fit equation for given data.

20. Plot vs Fit

 Plot → shows graph


 Fit → finds mathematical relation

💥 TRICKY QUESTIONS (WITH


STRONG ANSWERS)
Why Python is both compiled and interpreted?
Python code is first converted to bytecode (compiled) and then executed by interpreter.

List vs Array

 List → can store different types


 Array → stores same type, faster
MATHEMATICAL PHYSICS PRACTICAL (SEC -1)

What if indentation is wrong?


Python gives an error and program will not run.

Why NumPy is faster?


Because it uses optimized C implementation.

What is error in graph?


Difference between experimental value and true value.

You might also like