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

Python programs

The document contains several Python programs demonstrating basic programming concepts. These include swapping variables, converting units (kilometers to miles, Celsius to Fahrenheit), checking if a number is positive, negative, or zero, determining if a number is odd or even, checking for leap years, identifying prime numbers, and calculating the sum of the first 10 natural numbers. Each program includes user input and prints the result accordingly.

Uploaded by

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

Python programs

The document contains several Python programs demonstrating basic programming concepts. These include swapping variables, converting units (kilometers to miles, Celsius to Fahrenheit), checking if a number is positive, negative, or zero, determining if a number is odd or even, checking for leap years, identifying prime numbers, and calculating the sum of the first 10 natural numbers. Each program includes user input and prints the result accordingly.

Uploaded by

pr897099
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 swap two variables

P = int ( input("Please enter value for P: "))


Q = int ( input("Please enter value for Q: "))
temp = P
P=Q
Q = print ("The Value of P after swapping: ", P)
print ("The Value of Q after swapping: ", Q)

2.Python program to convert Kilometres to Miles


km = float (input ("Please enter the speed of car in Kilometre as a unit: "))
miles = km * 0.621371
print ("The kimetre in Miles: ", miles)

3.Python program to convert Celsius to


Fahrenheit
C= float (input("Temperature value in degree Celsius: " ))
F = (C * 9/5) + 32
print ("The Fahrenheit temperature is",F)

4.Python Program to check if a Number is


Positive, Negative or Zero
a = float(input("Enter a number as input value: "))
if a > 0:
print("Number given by you is Positive")
elif a < 0:
print("Number given by you is Negative")
else:
print("Number given by you is zero")
5.Python Program to Check if a Number is Odd
or Even
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("The number is Even number”)
else:
print(“The number is Odd number”)

6.Python Program to Check Leap Year


Year = int(input("Enter the number: "))
if((Year % 400 == 0) or
(Year % 100 != 0) and
(Year % 4 == 0)):
print("Given Year is a leap Year");
else:
print ("Given Year is not a leap Year")

7.Python Program to Check Prime Number


a = int(input("Enter an input number:"))
c=0
for i in range (1,a+1):
if(a%i==0):
c=c+1
if (c>2):
print("Not Prime")
else:
print("Prime")
break
else:
print (n)

8.Python Program to the sum of 1st 10 natural


numbers
sum=0
for i in range(1,11):
sum=sum+i
print(sum)

You might also like