Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

Python Programs

The document contains multiple Python programs demonstrating basic programming concepts. These include generating a multiplication table, checking if a number is positive, negative, or zero, determining leap years, summing natural numbers, checking divisibility, swapping variables, calculating the area of a triangle, and converting Celsius to Fahrenheit. Each program includes user input and prints the corresponding output.

Uploaded by

parulsah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Python Programs

The document contains multiple Python programs demonstrating basic programming concepts. These include generating a multiplication table, checking if a number is positive, negative, or zero, determining leap years, summing natural numbers, checking divisibility, swapping variables, calculating the area of a triangle, and converting Celsius to Fahrenheit. Each program includes user input and prints the corresponding output.

Uploaded by

parulsah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Python Program to Display the Multiplication Table

num = int(input(" Enter a number : "))


# using the for loop to generate the multiplication tables
print("Table of: ")
for a in range(1,11):
print(num,'x',a,'=',num*a)

2. Python Program to Check if a Number is Positive, Negative, or 0

n = float (input (“Enter the number: “))


if n > 0:
print (“The number provided is positive”)
elif n == 0:
print (“The number input is zero”)
else:
print (“The number provided is negative”)

3. Python Program to Check Leap Year

year = int (input (“Enter any year that is to be checked for leap year: “))
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print (“The given year is a leap year”)
else:
print (“It is not a leap year”)
else:
print (“It is not a leap year”)
else:
print (“It is not a leap year”)

4. Python Program to Find the Sum of Natural Numbers

n = int (input (“Enter any natural number: “)


if n < 0:
print (“Wrong input. Please enter a positive number.”)
else:
sum = 0
while (n > 0):
sum +=n
n -=1
print (“The sum of the natural numbers is: “, sum)
5. Python Program to Find Numbers Divisible by Another Number

num = int (input (“Enter the number whose divisibility needs to be checked:”))
div = int (input (“Enter the number with which divisibility needs to be checked:”))
if num%div == 0:
print (“The number is divisible.”)
else:
print (“The number is not divisible.”)

6. Python Program to Swap Two Variables

var1 = input (“Enter the first variable”)


var2 = input (“Enter the second variable”)
temp = var1
var1 = var2
var2 = temp
print (“The value of the first variable after swapping is:”, var1)
print (“The value of the second variable after swapping is:”, var2)

7. Python Program to Calculate the Area of a Triangle

p = float(input('Enter the length of first side: '))


q = float(input('Enter the length of second side: '))
r = float(input('Enter the length of final side: '))

# calculate the semi-perimeter


s = (p + q + r)/2

# calculate the area


area_tri = (s*(s-p)*(s-q)*(s-r)) ** 0.5
print('The area of the triangle is’,area_tri)

8. Python Program to Convert Celsius to Fahrenheit

print("Enter Temperature in Fahrenheit: ")


fahren = float(input())
celi = (fahren-32)/1.8
print("\nEquivalent Temperature in Celsius: ", celi)

You might also like