SlideShare a Scribd company logo
1 of 8
Download to read offline
Enter first number: 5
Enter second number: 5
10.0 is the sum
0.0 is the difference
25.0 is the multiplication
1.0 is the division
3125.0 is the exponent
In [1]: #1Compute sum, subtraction, multiplication, division and exponent of given variables input by the user.
a=float(input('Enter first number: '))
b=float(input('Enter second number: '))
c=a+b
d=a-b
e=a*b
f=a/b
g=a**b
print(c,"is the sum")
print(d,"is the difference")
print(e,"is the multiplication")
print(f,"is the division")
print(g,"is the exponent")
In [2]: #Compute area of following shapes: circle, rectangle, triangle, square, trapezoid and parallelogram.
#Area of circle
radius=5
pi=3.14
areac=pi*radius*radius
print("area of circle:",areac)
#Area of rectangle
length=20
breadth=35
arear=length*breadth
print("area of rectangle:",arear)
#Area of triangle
base=30
height=10
areat=base*height/2
print("area of triangle:",areat)
area of circle: 78.5
area of rectangle: 700
area of triangle: 150.0
area of square: 16
area of trapezoid: 112.5
area of parallelogram: 450
#Area of square
side=4
areas=side*side
print("area of square:",areas)
#Area of trapezoid
b1=10 #here x is base1 of trapezoid
b2=35 #here y is base2 of trapezoid
h1=5 #here h is height of trapezoid
areat=(b1+b2)/2*h1
print("area of trapezoid:",areat)
#Area of parallelogram
base1=10 #here base1 is base of parallelogram
height1=45 #here height is height of parallelogram
areap=base1*height1
print("area of parallelogram:",areap)
In [3]: #Compute volume of following 3D shapes: cube, cylinder, cone and sphere.
#Volume of a cube
scube=float(input('Enter side:'))
vcube=scube*scube*scube
print(vcube,"is the volume of cube")
#Volume of a cylinder
pi=3.14
rcyl=float(input('Enter radius of cylinder:'))
hcyl=float(input('Enter height of cylinder'))
vcyl=pi*rcyl*rcyl*hcyl
print(vcyl,"is the volume of cylinder")
#Volume of cone
pi=3.14
rco=float(input('Enter the radius of cone:'))
hco=float(input('Enter the height of cone:'))
vco=(pi*rco*rco*hco)/3
Enter side:5
125.0 is the volume of cube
Enter radius of cylinder:10
Enter height of cylinder5
1570.0 is the volume of cylinder
Enter the radius of cone:4
Enter the height of cone:6
100.48 is the volume of the cone
Enter the radius of sphere:122
7602350.293333333 is the volume of sphere
print(vco,"is the volume of the cone")
#Volume of sphere
pi=3.14
rsph=float(input('Enter the radius of sphere:'))
vsph=(4/3)*pi*rsph*rsph*rsph
print(vsph,"is the volume of sphere")
In [4]: #Compute and print roots of quadratic equation ax2+bx+c=0, where the values of a, b, and c are input by the user.
In [5]: #Print numbers up to N which are not divisible by 3, 6, 9,, e.g., 1, 2, 4, 5, 7,...
print("Numbers up to 100")
for number in range(0,101):
if number % 3 !=0 and number % 6 !=0 and number % 9 !=0:
print(number)
Numbers up to 100
1
2
4
5
7
8
10
11
13
14
16
17
19
20
22
23
25
26
28
29
31
32
34
35
37
38
40
41
43
44
46
47
49
50
52
53
55
56
58
59
61
62
64
65
67
68
70
71
73
74
76
77
79
80
82
83
85
86
88
89
91
92
94
95
97
98
100
Input the lengths of triangle
Enter the first side of triangle: 23
Enter the second side of triangle: 23
Enter the third side of triangle: 45
It is an isosceles triangle
In [6]: #Write a program to determine whether a triangle is isosceles or not?
print("Input the lengths of triangle")
side1=float(input("Enter the first side of triangle: "))
side2=float(input("Enter the second side of triangle: "))
side3=float(input("Enter the third side of triangle: "))
if side1==side2 or side2==side3 or side3==side1:
print("It is an isosceles triangle")
else:
print("error")
In [7]: #Print multiplication table of a number input by the user.
t=int(input("Enter the number of which you want the table :"))
Enter the number of which you want the table :12
12 X 0 = 0
12 X 1 = 12
12 X 2 = 24
12 X 3 = 36
12 X 4 = 48
12 X 5 = 60
12 X 6 = 72
12 X 7 = 84
12 X 8 = 96
12 X 9 = 108
12 X 10 = 120
Enter a natural number: 5
The sum is 5
The sum is 9
The sum is 12
The sum is 14
The sum is 15
for numbers in range(0, 11):
print(t,'X',numbers,'=',t*numbers)
In [11]: #Compute sum of natural numbers from one to n number.
natu=int(input('Enter a natural number: '))
if natu<0:
print("Please enter a positive number")
else:
sum=0
while natu>0:
sum+=natu
natu-=1
print("The sum is",sum)
In [10]: #Print Fibonacci series up to n numbers e.g. 0 1 1 2 3 5 8 13…..n
nterms=int(input("Enter number of terms :"))
n1,n2=0,1
count=0
if terms<=0:
print("please enter a positive number")
elif terms==1:
print("Fibonacci seq upto",terms,":")
print(n1)
else:
Enter number of terms :12
fibonacci seq :
0
1
1
2
3
5
8
13
21
34
55
89
Enter a natural number: 4
Answer is 1
Answer is 2
Answer is 6
Answer is 24
print("fibonacci seq :")
while count < nterms:
print(n1)
nth=n1+n2
n1=n2
n2=nth
count+=1
In [15]: #Compute factorial of a given number.
natu=int(input('Enter a natural number: '))
factorial=1
if natu<0:
print("Please enter a positive number")
elif natu==0:
print("Answer is 0")
for xx in range(1, natu+1):
factorial=factorial*xx
print("Answer is ",factorial)
In [5]: #Count occurrence of a digit 5 in a given integer number input by the user.
integer=[5,5,5,5,5,5,5]
integer.count(5)
7
Out[5]:
In [ ]:

More Related Content

Similar to Practical File waale code.pdf

Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdfYashMirge2
 
BUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdfBUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdfkarthikaparthasarath
 
tutorial5.ppt
tutorial5.ppttutorial5.ppt
tutorial5.pptjvjfvvoa
 
AI_Lab_File()[1]sachin_final (1).pdf
AI_Lab_File()[1]sachin_final (1).pdfAI_Lab_File()[1]sachin_final (1).pdf
AI_Lab_File()[1]sachin_final (1).pdfpankajkaushik2216
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfrajatxyz
 
fds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdffds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdfGaneshPawar819187
 
C programs
C programsC programs
C programsMinu S
 
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAM
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS  - SARASWATHI RAMALINGAMPROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS  - SARASWATHI RAMALINGAM
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
How You Can Read ISIN_
How You Can Read ISIN_How You Can Read ISIN_
How You Can Read ISIN_Theawaster485
 
Practice_Exercises_Control_Flow.pptx
Practice_Exercises_Control_Flow.pptxPractice_Exercises_Control_Flow.pptx
Practice_Exercises_Control_Flow.pptxRahul Borate
 

Similar to Practical File waale code.pdf (20)

Practicle 1.docx
Practicle 1.docxPracticle 1.docx
Practicle 1.docx
 
Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdf
 
BUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdfBUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdf
 
Python Tidbits
Python TidbitsPython Tidbits
Python Tidbits
 
p.pdf
p.pdfp.pdf
p.pdf
 
tutorial5.ppt
tutorial5.ppttutorial5.ppt
tutorial5.ppt
 
AI_Lab_File()[1]sachin_final (1).pdf
AI_Lab_File()[1]sachin_final (1).pdfAI_Lab_File()[1]sachin_final (1).pdf
AI_Lab_File()[1]sachin_final (1).pdf
 
Array
ArrayArray
Array
 
Ejer
EjerEjer
Ejer
 
ECE-PYTHON.docx
ECE-PYTHON.docxECE-PYTHON.docx
ECE-PYTHON.docx
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdf
 
fds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdffds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdf
 
C programs
C programsC programs
C programs
 
Array.pptx
Array.pptxArray.pptx
Array.pptx
 
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAM
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS  - SARASWATHI RAMALINGAMPROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS  - SARASWATHI RAMALINGAM
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAM
 
How You Can Read ISIN_
How You Can Read ISIN_How You Can Read ISIN_
How You Can Read ISIN_
 
Array in C.pdf
Array in C.pdfArray in C.pdf
Array in C.pdf
 
Array.pdf
Array.pdfArray.pdf
Array.pdf
 
Tech-1.pptx
Tech-1.pptxTech-1.pptx
Tech-1.pptx
 
Practice_Exercises_Control_Flow.pptx
Practice_Exercises_Control_Flow.pptxPractice_Exercises_Control_Flow.pptx
Practice_Exercises_Control_Flow.pptx
 

Recently uploaded

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Recently uploaded (20)

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Practical File waale code.pdf

  • 1. Enter first number: 5 Enter second number: 5 10.0 is the sum 0.0 is the difference 25.0 is the multiplication 1.0 is the division 3125.0 is the exponent In [1]: #1Compute sum, subtraction, multiplication, division and exponent of given variables input by the user. a=float(input('Enter first number: ')) b=float(input('Enter second number: ')) c=a+b d=a-b e=a*b f=a/b g=a**b print(c,"is the sum") print(d,"is the difference") print(e,"is the multiplication") print(f,"is the division") print(g,"is the exponent") In [2]: #Compute area of following shapes: circle, rectangle, triangle, square, trapezoid and parallelogram. #Area of circle radius=5 pi=3.14 areac=pi*radius*radius print("area of circle:",areac) #Area of rectangle length=20 breadth=35 arear=length*breadth print("area of rectangle:",arear) #Area of triangle base=30 height=10 areat=base*height/2 print("area of triangle:",areat)
  • 2. area of circle: 78.5 area of rectangle: 700 area of triangle: 150.0 area of square: 16 area of trapezoid: 112.5 area of parallelogram: 450 #Area of square side=4 areas=side*side print("area of square:",areas) #Area of trapezoid b1=10 #here x is base1 of trapezoid b2=35 #here y is base2 of trapezoid h1=5 #here h is height of trapezoid areat=(b1+b2)/2*h1 print("area of trapezoid:",areat) #Area of parallelogram base1=10 #here base1 is base of parallelogram height1=45 #here height is height of parallelogram areap=base1*height1 print("area of parallelogram:",areap) In [3]: #Compute volume of following 3D shapes: cube, cylinder, cone and sphere. #Volume of a cube scube=float(input('Enter side:')) vcube=scube*scube*scube print(vcube,"is the volume of cube") #Volume of a cylinder pi=3.14 rcyl=float(input('Enter radius of cylinder:')) hcyl=float(input('Enter height of cylinder')) vcyl=pi*rcyl*rcyl*hcyl print(vcyl,"is the volume of cylinder") #Volume of cone pi=3.14 rco=float(input('Enter the radius of cone:')) hco=float(input('Enter the height of cone:')) vco=(pi*rco*rco*hco)/3
  • 3. Enter side:5 125.0 is the volume of cube Enter radius of cylinder:10 Enter height of cylinder5 1570.0 is the volume of cylinder Enter the radius of cone:4 Enter the height of cone:6 100.48 is the volume of the cone Enter the radius of sphere:122 7602350.293333333 is the volume of sphere print(vco,"is the volume of the cone") #Volume of sphere pi=3.14 rsph=float(input('Enter the radius of sphere:')) vsph=(4/3)*pi*rsph*rsph*rsph print(vsph,"is the volume of sphere") In [4]: #Compute and print roots of quadratic equation ax2+bx+c=0, where the values of a, b, and c are input by the user. In [5]: #Print numbers up to N which are not divisible by 3, 6, 9,, e.g., 1, 2, 4, 5, 7,... print("Numbers up to 100") for number in range(0,101): if number % 3 !=0 and number % 6 !=0 and number % 9 !=0: print(number)
  • 4. Numbers up to 100 1 2 4 5 7 8 10 11 13 14 16 17 19 20 22 23 25 26 28 29 31 32 34 35 37 38 40 41 43 44 46 47 49 50 52 53 55 56 58 59 61 62 64
  • 5. 65 67 68 70 71 73 74 76 77 79 80 82 83 85 86 88 89 91 92 94 95 97 98 100 Input the lengths of triangle Enter the first side of triangle: 23 Enter the second side of triangle: 23 Enter the third side of triangle: 45 It is an isosceles triangle In [6]: #Write a program to determine whether a triangle is isosceles or not? print("Input the lengths of triangle") side1=float(input("Enter the first side of triangle: ")) side2=float(input("Enter the second side of triangle: ")) side3=float(input("Enter the third side of triangle: ")) if side1==side2 or side2==side3 or side3==side1: print("It is an isosceles triangle") else: print("error") In [7]: #Print multiplication table of a number input by the user. t=int(input("Enter the number of which you want the table :"))
  • 6. Enter the number of which you want the table :12 12 X 0 = 0 12 X 1 = 12 12 X 2 = 24 12 X 3 = 36 12 X 4 = 48 12 X 5 = 60 12 X 6 = 72 12 X 7 = 84 12 X 8 = 96 12 X 9 = 108 12 X 10 = 120 Enter a natural number: 5 The sum is 5 The sum is 9 The sum is 12 The sum is 14 The sum is 15 for numbers in range(0, 11): print(t,'X',numbers,'=',t*numbers) In [11]: #Compute sum of natural numbers from one to n number. natu=int(input('Enter a natural number: ')) if natu<0: print("Please enter a positive number") else: sum=0 while natu>0: sum+=natu natu-=1 print("The sum is",sum) In [10]: #Print Fibonacci series up to n numbers e.g. 0 1 1 2 3 5 8 13…..n nterms=int(input("Enter number of terms :")) n1,n2=0,1 count=0 if terms<=0: print("please enter a positive number") elif terms==1: print("Fibonacci seq upto",terms,":") print(n1) else:
  • 7. Enter number of terms :12 fibonacci seq : 0 1 1 2 3 5 8 13 21 34 55 89 Enter a natural number: 4 Answer is 1 Answer is 2 Answer is 6 Answer is 24 print("fibonacci seq :") while count < nterms: print(n1) nth=n1+n2 n1=n2 n2=nth count+=1 In [15]: #Compute factorial of a given number. natu=int(input('Enter a natural number: ')) factorial=1 if natu<0: print("Please enter a positive number") elif natu==0: print("Answer is 0") for xx in range(1, natu+1): factorial=factorial*xx print("Answer is ",factorial) In [5]: #Count occurrence of a digit 5 in a given integer number input by the user. integer=[5,5,5,5,5,5,5] integer.count(5)