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

assignment_python_aditya1328

Uploaded by

asshinde1023
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)
12 views

assignment_python_aditya1328

Uploaded by

asshinde1023
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/ 8

Assignment No: 1

Name: Shinde Aditya Sanjay


Div: B Roll No:169

1 SET A
1)Python Program to calculate Area of Triangle

[2]: a=int(input("Enter the Height "))


b=(int(input("Enter the base ")))
c=(0.5*b*a)
print("Area of triangle=",c)

Enter the Height 9


Enter the base 3
Area of triangle= 13.5
2)Python Program to Swap two variables

[3]: c=int(input("Enter the first variable "))


d=int(input("Enter the second variable "))
temp=c
c=d
d=temp
print("The first variable after swapping is ",c)
print("The second variable after swapping is ",d)

Enter the first variable 4


Enter the second variable 2
The first variable after swapping is 2
The second variable after swapping is 4
3)Python program to generate random numbers

[6]: import random


a=(random.randint(0,100))
print("random number between 0 to 100 is ",a)

random number between 0 to 100 is 9

1
2 SET B
1)Write a python program to check if a number is Positive,Negative or zero

[9]: a=int(input("Enter the number"))


if(a<0):
{
print("The number is negative")
}
elif(a>0):
{
print("The number is positive")
}
elif(a==0):
{
print("The number is zero")
}

Enter the number1


The number is positive

[10]: a=int(input("Enter the number"))


if(a<0):
{
print("The number is negative")
}
elif(a>0):
{
print("The number is positive")
}
elif(a==0):
{
print("The number is zero")
}

Enter the number-2


The number is negative

[11]: a=int(input("Enter the number"))


if(a<0):
{
print("The number is negative")
}
elif(a>0):
{
print("The number is positive")
}
elif(a==0):

2
{
print("The number is zero")
}

Enter the number0


The number is zero
2)Write a Python program to check if a number is odd or even

[14]: b=(int(input("Enter the number")))


if(b%2==0):
{
print("The Number is Even")
}
else:
{
print("The number is Odd")
}

Enter the number2


The Number is Even

[15]: b=(int(input("Enter the number")))


if(b%2==0):
{
print("The Number is Even")
}
else:
{
print("The number is Odd")
}

Enter the number3


The number is Odd
3)Write a Python Program to check prime number

[24]: a=int(input("enter a number greater than 2 "))


for i in range(2,a):
if (a % i)==0:

print("The number is not prime")


break
else:

print("The number is prime")

enter a number greater than 2 4


The number is not prime

3
[25]: a=int(input("enter a number greater than 2 "))
for i in range(2,a):
if (a % i)==0:

print("The number is not prime")


break
else:

print("The number is prime")

enter a number greater than 2 3


The number is prime
4)Write a python program to check armstrong number

[2]: a=int(input("Enter a number "))


order = len(str(a))
sum = 0
temp = a
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10

# display the result


if a == sum:
print(a,"is an Armstrong number")
else:
print(a,"is not an Armstrong number")

Enter a number 153


153 is an Armstrong number

[3]: a=int(input("Enter a number "))


order = len(str(a))
sum = 0
temp = a
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10

# display the result


if a == sum:
print(a,"is an Armstrong number")
else:
print(a,"is not an Armstrong number")

4
Enter a number 16
16 is not an Armstrong number
5)Write a python program to find the factorial of a number

[4]: def factorial(x):


if x == 1 or x == 0:
return 1
else:
return (x * factorial(x-1))
a= int(input("Enter a number: "))
result = factorial(a)
print("The factorial of", a, "is", result)

Enter a number: 5
The factorial of 5 is 120

3 PROGRAMS FOR PRACTICE


1)Python program to convert kilometers to miles

[6]: km = float(input("Enter value in kilometers: "))


# 1 Kilometer =0.621371 miles
a = 0.621371
m = km * a
print('%f kilometers is equal to %f miles' %(km,m))

Enter value in kilometers: 10


10.000000 kilometers is equal to 6.213710 miles
2)Python program to convert celcius to Fahrenhit

[8]: a=int(input("Enter the temprature into celcius "))


#Formula for conversion of celcius into farenheit
f = (a * 1.8) + 32
print("The temprature into farenheit is ",f)

Enter the temprature into celcius 23


The temprature into farenheit is 73.4
3)Write a python program to check leap year

[10]: year=int(input("Enter year too check "))


if((year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)):
print("The year is leap year")
else:
print("The year is not leap year")

Enter year too check 2025


The year is not leap year

5
[11]: year=int(input("Enter year too check "))
if((year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)):
print("The year is leap year")
else:
print("The year is not leap year")

Enter year too check 2024


The year is leap year
4)Write a python program to print all prime numbers in an interval

[13]: a=int(input("Enter the first number "))


b=int(input("Enter the last number "))

print("Prime numbers between", a, "and", b, "are:")

for num in range(a, b + 1):


if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
print(num)

Enter the first number 1


Enter the last number 100
Prime numbers between 1 and 100 are:
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73

6
79
83
89
97
5)Write a python program to print the fibonacci sequence

[14]: n =int(input("How many number sequence you want "))


num1 = 0
num2 = 1
next_number = num2
count = 1
while count <= n:
print(next_number, end=" ")
count += 1
num1, num2 = num2, next_number
next_number = num1 + num2
print()

How many number sequence you want 10


1 2 3 5 8 13 21 34 55 89
6)Write a puthon program to find Armstrong number in an interval

[21]: a=int(input("Enter the first number "))


b=int(input("Enter the last number "))
for num in range(a, b + 1):
order = len(str(num))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if num == sum:
print(num)

Enter the first number 1


Enter the last number 1000
1
2
3
4
5
6
7
8
9
153

7
370
371
407
7)Write a Python Program to find sum of Natural Numbers

[26]: num =int(input("Enter a Number you want sum till "))


sum = 0
while(num > 0):
sum += num
num -= 1
print("The sum of all natural numbers", sum)

Enter a Number you want sum till 100


The sum of all natural numbers 5050

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