0% found this document useful (0 votes)
10 views

Eben

Uploaded by

Sherin Varghese
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)
10 views

Eben

Uploaded by

Sherin Varghese
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
You are on page 1/ 6

Module 1

Basics of Python

Name : Eben Varghese Date:24-7-24


Class : SY (comps) Batch: A3
Roll No : 58
Div : A

Theory Question:

1.List the different modes of running python scripts?


A) Interactive Mode: Ideal for testing small snippets of code and experimenting.
Script Mode: Suitable for executing complete programs.

2.Mention five Applications and features of Python. A)


Applications:
1) Web Development: Used for building dynamic websites and web applications.
2)Data Science and Machine Learning: Utilized for creating machine learning models.
3)Automation and Scripting: Simplifies writing scripts with its easy-to-read syntax.
4)Game Development: Applied in prototyping and developing games.
5)Scientific Computing: Used for simulations and data analysis in research.

Features:
1)Easy to Read and Write: Python has a simple and clean syntax, making it easy to
learn and use
2) Object-Oriented: Python supports object-oriented programming, which promotes code
reuse and modularity.
3)Robust Frameworks and Libraries: Python offers powerful frameworks and libraries
for web development , data science , machine learning and more.
4)Cross-Platform Compatibility: Python runs on various operating systems (Windows,
macOS, Linux) without requiring significant changes to the code.
5)Dynamically Typed: Variables in Python do not require explicit declaration, allowing
for flexible and rapid development.

3.List the differences between compiler and interpreter? A)


1) Translation Process:
• Compiler: Translates the entire source code into machine code before execution.
• Interpreter: Translates and executes code line by line at runtime. 2)Execution
Speed:
• Compiler: Faster execution since the code is pre-translated.
• Interpreter: Slower execution due to on-the-fly translation. 3)Error Detection:
• Compiler: Detects all errors before execution.
• Interpreter: Detects errors during execution, stopping at each error.
4.What are the supported data types in Python?
A) Numeric types (int, float, complex), string (str), boolean (bool), and collection types (list,
tuple, set).

5. Is it a python programming language or a scripting language? justify your statement


A) Python is both a programming and scripting language.
Justification: Python is a versatile language used for writing complete applications
(programming) and for automating tasks and running scripts (scripting). Its ability to handle
complex software development and its use in quick automation tasks demonstrate its dual
nature.

6.How to represent complex numbers in python?


A) Complex numbers are represented using the complex type.
Ex. a = 3 + 4j, b = -2 - 5j
3 is the real part, and 4j is the imaginary part.

7.What is the importance of type conversion?


A) Type conversion is crucial for ensuring data compatibility, avoiding errors, and enabling
interactions between different data types.

8.How to determine the type of a variable in Python?


A) To determine the type of a variable in Python, use the built-in type() function.

9.What is the indentation error? Explain with an example?


A) An indentation error occurs when the levels of indentation in the code are inconsistent or
incorrect, causing a syntax error. Python relies on indentation to define blocks of code.
Example:
def greet(name):
print("Hello, " + name)
In this example, the print statement is not indented correctly under the def block, which will
raise an ‘IndentationError’. Correct indentation would be: def greet(name):
print("Hello, " + name)

10. Write a print statement to display the output Hello ”World” Everyone.
A)

11. List 5 app developed using python


A) Instagram, Spotify, Quora, YouTube, Netflix [backend infrastructure].

Experiment -1A

Aim: Write a program to demonstrate different basic data types in python

Program:

i=7 c=24+8j
f=70.1
s=”HELLO” b=
True
print("the value of c is:",i,'\nits type is:',type(i))
print("the value of c is:",f,'\nits type is:',type(f)) print("the
value of c is:",c,'\nits type is:',type(c)) print("the value of
c is:",s,'\nits type is:',type(s)) print("the value of c
is:",b,'\nits type is:',type(b)) Output:

Experiment 1B

Aim: Write a program to perform different arithmetic operations on numbers in python.

Program:

a=10; b=3
print("Addition of a:",a,"&b:",b,"is:",a+b)
print("Subtraction of a:",a,"&b:",b,"is:",a-b)
print("Multiplication of a:",a,"&b:",b,"is:",a*b)
print("Floor Division of a:",a,"&b:",b,"is:",a/b)
print("Int division of a:",a,"&b:",b,"is:",a//b)
print("Modulus of a:",a,"&b:",b,"is:",a%b)
print("exponent of a:",a,"&b:",b,"is:",a**b)

Output:

Experiment 1C

Aim:Write a program that takes an amount in euro as input. You need to find its
equivalent in Indian rupee and display it. Assume 1 euro= Rs. 78.85
Program :
x=eval(input("Enter the value of Euro")) Rs=x*78.85
print("Amount of", x ,"Euro is",Rs,"Rupee" )

Output :
Enter the value of Euro1
Amount of 1 Euro is 78.85 Rupee
Enter the value of Euro 10
Amount of 100 Euro is 788.4999999999999 Rupee

Output:

Experiment 1D

Aim:Write a python program to swap two numbers and check if the first number is positive
or negative or zero.

Program:
print("Program for Swapping two numbers")
a=int(input("Enter first no:"))
b=float(input("Enter second no:"))
print("Before swapping a=",a," b=",b) a,b=b,a
print("After swapping a=",a," b=",b)

#To check numbers


a=int(input("Enter first no a="))
b=float(input("Enter second no b=")) if
b>0:

print("b is positive")
# print("{0} is Positive".format(a))
elif
b<0:
"b is negative"
print()
else:
"b is 0" print()
/*if a>0:
print("a is positive") elif
a<0:
"a is negative"
print() else:
"a is 0" print()
*/
Output:

Experiment 1E

Aim : Write a python program to convert temperature to and from Celsius to fahrenheit

Program:

while(1):
print("1.CELSIUS TO FAHRENHEIT\n2.FAHRENHEIT TO CELSIUS\n3.EXIT\n")
choice=input("ENTER YOUR CHOICE:")
ch=int(choice) if(ch==1):
c=int(input("ENTER TEMPERATURE IN CELSIUS:")) f=((9*c)/5)+32
print("converted temperature is:",f)
elif(ch==2):
f=int(input("ENTER TEMPERATURE IN FAHRENHEIT:")) c=((f-32)/9)*5
print("converted temperature is:",c)
elif(ch==3): exit()
else:
print("wrong choice")

Output:
Exercise
1. Write a Python program to display your name using Interactive Mode
2.Write a Python program to display “PCE” using Script Mode
3.Write a program to calculate area and perimeter of the square.Accept side from user.
4.Write a program to find out absolute value of an input number
5.Write a Python program to calculate factorial of a number(While,For)

Conclusion:

You might also like