Unit 1
# 1. Write a program to swap two numbers without taking a temporary variable.
a,b=[int(i) for i in input("Enter Two Number : ").split()]
print(a,b)
a,b = b,a
print(a,b)
# 1. Write a program to swap two numbers without taking a temporary variable.
a,b=[int(i) for i in input("Enter Two Number : ").split()]
print(a,b)
a,b = b,a
print(a,b)
# 5. Write a program to find out and display the common and the non common
# elements in the list using membership operators
a=[]
b=[]
n=int(input("enter how many element"))
for i in range(0,n):
a.append(input("enter element A"))
b.append(input("enter element B"))
seta=set(a)
setb=set(b)
if seta & setb:
print("common Element are :",seta & setb)
if seta ^ setb:
print("non common Element are :",seta ^ setb)
''' 6. Create a program to display memory locations of two variables using id()
function, and then use identity operators two compare whether two objects
are same or not.'''
a,b=[int(i) for i in input("Enter Two Number : ").split()]
print("Memory location of a is : ",id(a))
print("Memory location of b is : ",id(b))
if a is b:
print("Same")
else:
print("Not Same")
''' 8. Write a python program to find the sum of even numbers using command line
arguments.'''
import sys
a = sys.argv
print("argument is -> " , a)
print("---------")
t = 0
for i in a[1:]:
t = t + int(i)
print(t)
'''
9. Write a menu driven python program which perform the following:
Find area of circle
Find area of triangle
Find area of square and rectangle
Find Simple Interest Exit. '''
import math
while 1:
print("1. area of circle")
print("2. area of triangle")
print("3. are of squere and rectangle")
print("4. Simple Interest ")
print("5. Exit")
ch = int(input("Enter choise "))
if ch == 1:
p = int(input("Enter Radious:"))
print(p * p * math.pi)
elif ch == 2:
n1 = int(input("Enter N1 :"))
n2 = int(input("Enter N2 :"))
n3 = int(input("Enter N3 :"))
t = n1 + n2 + n3 / 2
s = t*(n1 - t)*(n2 - t)*(n3 - t) ** 0.5
print(s)
elif ch == 3:
s = int(input("Enter no of Squere:"))
l = int(input("Enter lengh:"))
w = int(input("Enter width:"))
print("Squere is = ",s*s)
print("Rectangle is = ",l*w)
elif ch == 4:
p = int(input("Enter Price :"))
r = int(input("Enter Rate :"))
n = int(input("Enter year :"))
print(p * r * n / 100)
elif ch == 5:
exit(0)
'''
11. Write a program to search an element in the list using for loop and
also demonstrate the use of “else” with for loop. '''
l = [1,5,10,15,20,25]
print("List is = ", l)
s = int(input("Enter Search Element:"))
for i in l:
if s == i:
print("find element")
break;
if s != int(i):
print("not find")
''' 12. Write a python program that asks the user to enter a length in centimeters.
If the user enters a negative length, the program should tell the user
that the entry is invalid. Otherwise, the program should convert the
length to inches and print out the result. (2.54 = 1 inch)'''
print("Convert inch into Centimeter")
inch = float(input("Enter inch "))
if inch > 0:
t = inch * 2.54
print(t)
else:
print("Invalid Number ")
cent = float(input("Enter Centementer "))
if cent > 0:
t = cent / 2.54
print("ans is %.2f"%t)
else:
print("Invalid Number ")

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home