0% found this document useful (0 votes)
1 views2 pages

Python Codes 76

Uploaded by

SAAD
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)
1 views2 pages

Python Codes 76

Uploaded by

SAAD
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/ 2

PYTHON CODES

Class: VII
Compiler: https://replit.com/languages/python3

Convert Kilometers to Miles:


# Taking kilometers input from the user
kilometers = float(input("Enter value in kilometers: "))

# Conversion factor
conv_fac = 0.621371

# Calculate miles
miles = kilometers * conv_fac

# Print statement
print("%0.2f kilometers is equal to %0.2f miles" % (kilometers, miles))

Calculate Area of a Triangle:


# Python Program to find the area of a triangle
a=5
b=6
c=7

# Uncomment below to take inputs from the user


# a = float(input('Enter first side: '))
# b = float(input('Enter second side: '))
# c = float(input('Enter third side: '))

# Calculate the semi-perimeter


s = (a + b + c) / 2

# Calculate the area using Heron's formula


area = (s * (s - a) * (s - b) * (s - c)) ** 0.5

# Print the result


print('The area of the triangle is %0.2f' % area)

Covert Celsius to Fahreheit:


# Python Program to convert temperature from Celsius to Fahrenheit

# Assigning a value to Celsius


celsius = 37.5 # Use '=' instead of '<='

# Calculate Fahrenheit
fahrenheit = (celsius * 1.8) + 32 # Use '*' for multiplication and '=' for
assignment

# Print the result


print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %
(celsius, fahrenheit))

Check if a Number is Negative, Positive or 0:


# Python program to check if a number is positive, negative, or zero

# Taking input from the user


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

# Checking conditions
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")

Check if a Number is Odd or Even:


# Python program to check if the input number is odd or even.

# Taking input from the user


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

# Checking if the number is even or odd


if (num % 2) == 0:
print("{0} is Even".format(num))
else:
print("{0} is Odd".format(num))

You might also like