Wednesday 31 January 2018

Perform concatenation operation

Select any two words and perform concatenation operation

# Select any two words and perform concatenation operation

str1 = raw_input("Enter first word :")
str2 = raw_input("Enter second word :")

str3 = str1 + str2

print "Concatenation of Two Words is :",str3


Tuesday 29 November 2016

# Choose any value and find whether the number is even or odd.

n = int (input ("Enter any value to check number is even or odd : "))

if (n % 2) == 0 :
    print "Given Number :",n," is even number"
else:
    print "Given Number :",n," is odd number"



Output : 

Enter any value to check number is even or odd : 34
Given Number : 34  is even number

To calculate Kinetic Energy of an object


# To calculate Kinetic Energy of an object

#Input

mass = float(input("Enter the value of Mass: "))
velocity = float(input("Enter the value of velocity :"))

# Calculation

ke = float(1)/2 * mass * (velocity ** 2)

#print

print "Kinetic Energy of an object is : ",ke,"Joule"


Output

Enter the value of Mass: 34.52
Enter the value of velocity :424.2
Kinetic Energy of an object is :  3105861.7464 Joule

Show the distance in miles per gallon with respect user defined value in Python.

#Show the distance in miles per gallon with respect user defined value in Python.
#input

km = float(input("Enter the distance in KM: ")) 
gallon = float(input("Enter the gas
utilisation in gallon :"))

#calculation

miles = km * 0.621
mile_per_gallon = (miles/gallon)

#print of result

print "Miles per Gallon of Given data is :",mile_per_gallon



Output 

Enter the distance in KM: 345
Enter the gas utilisation in gallon :343.66
Miles per Gallon of Given data is : 0.623421404877

Perform Arithmetic Operation using Python.

#Assignment No : 1(A)
# Perform Arithmetic Operation using Python.

n1 = int(input("Enter first Number:"))  # string --> int
n2 = int(input("Enter Second Number:"))  # string --> int

n3 = n1+n2
n4 = n1-n2
n5 = n1*n2
n6 = float (n1)/n2
n7 = n1%n2

print "Addition of Two number is :",n3
print "Subtraction of Two number is :",n4
print "Multiplication of Two number is :",n5
print "Division of Two number is :",n6


Output :

Enter first Number:12
Enter Second Number:343
Addition of Two number is : 355
Subtraction of Two number is : -331
Multiplication of Two number is : 4116
Division of Two number is : 0.0349854227405







Program for Addition of Two Numbers in Python


# Addition of Two Number  

num1 = int(input("Enter first number :"))   # Here we take first number
num2 = int(input("Enter Second number :"))   # Here we take second number

num3 = num1 + num2    #perform addtion of two Number

print "Addition of Two Number is ", num3     #print the result.

Output

Enter first number : 12
Enter Second number : 10

Addition of Two Number is 22