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

Chapter 2 Getting Started With Python

The document provides an introduction to Python, including its history, features, and applications. It covers basic programming concepts, the difference between interactive and script modes, and the roles of compilers and interpreters. Additionally, it includes examples of Python print statements and basic input/output programs.
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)
4 views

Chapter 2 Getting Started With Python

The document provides an introduction to Python, including its history, features, and applications. It covers basic programming concepts, the difference between interactive and script modes, and the roles of compilers and interpreters. Additionally, it includes examples of Python print statements and basic input/output programs.
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

COMPUTER SCIENCE WITH PYTHON

CHAPTER-GETTING STARTED WITH PYTHON


Q1. Write a short note on Python.
1. Python is a programming language developed by Guido Van Rossum in 1991 at
the National Research Institution for Mathematics in the Netherlands.
2. Python is based on ABC language, a teaching language created to replace of the
BASIC programming language.
3. It was named after the BBC comedy show Monty Python’s Flying Circus.

Q2. List the advantages/ features of Python.


1. Platform-independent or portable language: Python can run across different
platforms -Windows, Linux/UNIX, Mac OS and other operating systems.
2. Readability: Python programs are simple, concise, English-like, and easy to read
and understand.
3. Object Oriented Language: Python is an interactive, interpreted (executes the
code line by line at a time making it easy-to-debug language) and object oriented
language.
4. Free and Open Source: Python language is freely available and can be easily
downloaded from http://www.python.org.
5. Ample availability of Libraries: Python has small codes with simpler syntax as
compared to C++, JAVA and has extensive repository of libraries to solve the task.

Q3. List the usage/applications of Python.


Python is used by Google search engine, YouTube, Netflix, Spotify, Dropbox, Instagram
etc. Python is being used in many diverse fields/applications like System programming,
GUI Programming, internet scripting, web gaming, text processing, network
programming, commercial robots and in space, scientific applications.

Q4. What is a program?


A complete set of instructions written using a programming language is termed as
program.

Q5. What is IDLE?


Integrated Development Learning Environment allows the user to edit, run, browse and
debug a python program from a single interface. Python IDLE comprises of Interactive
mode and Script mode.

Q6. Define Python Shell.


The interactive interpreter of Python is termed as Python Shell.

Q7. What is the difference between interactive mode and script mode in Python?
In interactive mode, instructions are given in front of Python prompt (>>> or In[ ]:) in
Python shell. Python carries out the given instruction and shows the result there itself.
In script mode, Python instructions are stored in a file with .py extension and are
executed together in one go as a unit known as Python program.

Page 1 of 6
COMPUTER SCIENCE WITH PYTHON

Q8. State the difference between compiler and interpreter.


INTERPRETER COMPILER
Interpreter is a language processor that Compiler is a language processor that
converts a HLL (High Level Language) converts the HLL program into
program into machine language line by machine language in one go.
line.
If there is any error in any line, it reports It reports all the errors of the
it at the same time and program program along with the line numbers.
execution cannot resume until the error After all the errors are removed, the
is rectified. program is recompiled.
Interpreter must always be present in the After the compilation, compiler is not
memory every time the program is needed in the memory as the object
executed as every time the program is program is available.
run, it is first interpreted and then
executed.

NOTE:
➢ Press F5 or Run → Run Module to run a program in script mode.
➢ Extension of python files is .py or .pyw
➢ Python is a case sensitive language as it treats upper and lower case
characters differently.
➢ Strings can come in single quotes(' ') or double quotes(" ")
➢ >>> is called as Python command prompt or prompt.

Q9. Why is python interpreted?


Python is interpreted because the program is processed at runtime by the interpreter
and you do not need to compile your program before executing it.

Q10. Explain print().


print() is a function to display the specified content on the screen.
print(value(s), sep=' ', end='\n')
where sep= String inserted between values by default, a space.
end: String appended after the last value by default, a new line.

Q11. Give the output for the following:


print(10,20,30) print(70,45,78, sep='*-') print("Hello") print(3*7) print(4+7)
10 20 30 70*-45*-78 Hello 21 11

print(9.6) print(15,20,25, sep='\t') print(60,70,80, sep='\n') Print('oops')


9.6 15 20 25 60 error
70
80
print('cat', 'cow', 'dog', sep=',' end='##') print(n=34) print(20/4*5+8-10)
cat, cow, dog## error 23.0
print(4.5, 'Hi', 5-7, 'python', 15/2) print(3+8.0+6*12)
4.5 Hi -2 python 7.5 83.0

print( ) statement without any arguments will simply jump to the next line.

Page 2 of 6
COMPUTER SCIENCE WITH PYTHON
Python print Programs

# To print personal information like Name, Father’s Name, Class, School Name
print ("My name is Riya Verma")
print ("My Father’s name is Mr. Sunil Verma")
print ("I am in class XI")
print ("I study in CRPF Public School")

# To print the following pattern using multiple print commands


*
* *
* * *
* * * *
* * * * *
print ("*")
print ("*\t*")
print ("*\t*\t*")
print ("*\t*\t*\t*")
print ("*\t*\t*\t*\t*")

# To print the following pattern using multiple print commands


*****
****
***
**
*
print ("*****")
print ("****")
print ("***")
print ("**")
print ("*")

# To find square of number 7


print("Square of 7=", 7**2)

# To find the sum of two numbers 15 and 20.


a=15
b=20
print("Sum of two numbers=", a+b)

# To convert length given in kilometers into meters.


km=8
m=km*1000
print(km, "Kilometers =", m, "meters")

# To print the table of 5 up to five terms.


print("5 x 1 =", 5*1)
print("5 x 2 =", 5*2)
print("5 x 3 =", 5*3)
print("5 x 4 =", 5*4)
print("5 x 5 =", 5*5)
Page 3 of 6
COMPUTER SCIENCE WITH PYTHON
# To calculate Simple Interest if the principle_amount = 2000 rate_of_interest =
4.5 time = 10
p=2000
r=4.5
t=10
si= (p*r*t)/100
print ("Simple interest = " ,si)

#to print a bill


print("\t\tBILL")
print ("\t\t****")
print ("S.No.\t Item\t Quantity\t Price")
print ("1.\t Chalk\t 5\t\t 3")
print ("2.\t Duster\t 10\t\t 35")
print ("3.\t Marker\t 50\t\t 45")

Python Basic Input/ Output Programs

#to find the sum of 2 numbers


a=int(input("Enter first number"))
b=int(input("Enter second number"))
c=a+b
print("The sum of 2 numbers is ", c)

#to find the area of rectangle


l=int(input("Enter length "))
b=int(input("Enter breadth "))
area=l*b
print("The area of rectangle is ", area)

#to find the area of square


s=int(input("Enter side "))
area=s*s
print("The area of square is ", area)

#to find the area and perimeter of circle


r=float(input("Enter radius "))
area=3.14*r*r
peri= 2*3.14*r
print("The area of circle is ", area)
print("The perimeter of circle is ", peri)

#to find the area of triangle


b=float(input("Enter base "))
h=float(input("Enter height "))
area=0.5*b*h
print("The area of triangle is ", area)

#to find the perimeter of rectangle and square


l=int(input("Enter length "))
b=int(input("Enter breadth "))
Page 4 of 6
COMPUTER SCIENCE WITH PYTHON
s=int(input("Enter side "))
perir=2*(l+b)
peris=4*s
print("The perimeter of rectangle is ", perir)
print("The perimeter of square is ", peris)

#to find the volume of sphere


r=float(input("Enter radius "))
vol=4/3 *3.14 * pow(r,3)
print("The volume of sphere is ", vol)

#to find the sum, product, difference and quotient of two entered numbers
num1=float(input("Enter first number "))
num2=float(input("Enter second number "))
print("The sum of two numbers is ", num1 + num2)
print("The difference of two numbers is ", num1 - num2)
print("The product of two numbers is ", num1 * num2)
print("The quotient of two numbers is ", num1 / num2)

'''calculate salary if da is 15% of basic salary, hra is 10% of basic salary, ta is 5% of


basic salary and pf is 2% of basic salary'''
basic= int(input("Enter the basic salary "))
da=0.15*basic
hra=0.10*basic
ta=0.05*basic
pf=0.02*basic
netsal=basic+da+hra+ta-pf
print("Total salary= ", netsal)

#To read the temperature in Celsius and display it in Fahrenheit and Kelvin
c=float(input("Enter temperature in Celsius "))
f= c * 9/5 + 32
k= c + 273.15
print ("The temperature in Fahrenheit = " , f)
print ("The temperature in Kelvin = " , k)

#To calculate simple interest


p=float(input("Enter principle "))
r=float(input("Enter rate "))
t=float(input("Enter time "))
si= (p*r*t)/100
print ("Simple interest = " ,si)

#To find the remainder of two numbers


a=int(input("Enter first number"))
b=int(input("Enter second number"))
print ("The remainder =", a%b)

# To convert the length entered in meters to centimeter, millimeter and kilometer


m=float(input("Enter length in meters "))
cm=m*100
Page 5 of 6
COMPUTER SCIENCE WITH PYTHON
mm=m*1000
km=m/1000
print ("Length in centimeters = " , cm)
print ("Length in millimeters = " , mm)
print ("Length in kilometers = " , km)

#Find the area of triangle using Heron’s formula


import math
a=int(input("Enter first side of triangle "))
b=int(input("Enter second side of triangle "))
c=int(input("Enter third side of triangle "))
s=(a+b+c)/2
area= math.sqrt(s*(s-a)*(s-b)*(s-c))
print("Area of Triangle= ", area)

#To find square, cube and fourth power of a number


a=int(input("Enter the number "))
print ("Square of the number= ", a**2)
print ("Cube of the number= ", a**3)
print ("Fourth power of the number= ", a**4)

#Swap two numbers without using third variable


a=int(input("Enter first number "))
b=int(input("Enter second number "))
b, a=a, b
print("New Value of first number =", a)
print("New Value of second number =", b)

#Accept marks in five subjects and output average marks.


e=int(input("Enter marks in English "))
h=int(input("Enter marks in Hindi "))
m=int(input("Enter marks in Maths "))
sc=int(input("Enter marks in Science "))
ss=int(input("Enter marks in Social Science "))
total=e+h+m+sc+ss
avg=total/5
print("Average marks in 5 subjects =", avg)

#To find X raised to the power n


x= int(input("Enter a number "))
n=int(input("Enter power "))
power=x**n
print("x raised to the power n =", power)

Page 6 of 6

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy