1.
Program Using variables of different data types
num=int(input("Enter the value of num:"))
amt=float(input("Enter the value of amt:"))
pi=float(input("Enter the value of pi:"))
code=str(input("Enter the value of code:"))
Boolean=bool(input("Enter the value of BooleanT/F :"))
print("/n",num,"/n",amt,"/n",pi,"/n",code,"/ n",Boolean)
Output:
Enter a value of num : 9
Enter a value of amt : 900000
Enter a value of pi : 400000
Enter a value of code: 628
Enter a value of boolean : T
9
900000.0
400000.0
628
True
[Link] using operators
n1=int(input("Enter the first number is:"))
n2=int(input("Enter the second number is:"))
add=n1 + n2
print("The addition of ",n1," and ",n2,"is:",add)
sub=n1 - n2
print("The subtraction of",n1," and ",n2,"is:",sub)
mul=n1 * n2
print=("The multiplication of the numbers ",n1,"
and ",n2,"is :",mul)
div=n1 / n2
print=("The division of",n1," and ",n2,"is:",div)
rem=n1 % n2
print("The remainder of ",n1," and ",n2,"is:",rem)
div1=n1 / n2
print("The division of ",n1," and ",n2,"is:",div1)
Output
Enter the first number: 9
Enter the second number: 10
The addition of 9 and 10 is : 19
The subtraction of 9 and 10 is : -1
The multiplication of 9 and 10 is : 90
The division of 9 and 10 is : 0.9
The remainder of 9 and 10 is : 9
The division of 9.0 and 10 is : 0.9
[Link] usage condisional statement to check
a character is vowel or not
ch=input("Enter any charactors:")
if (ch == "A" or ch == "I" or ch == "E" or ch ==
"O" or ch == "U"):
print(ch ,"is a vowel")
elif ( ch == "a" or ch == "i" or ch == "e" or ch ==
"u"):
print(ch, "is a vowel")
else:
print(ch,"is not a vowel")
Output
Enter any character : k
is not a Vowel
[Link] to find the factorial of number using
loops
num=int (input ("Enter a no:"))
if(num==0):
fact=1
fact=1
for i in range(1,num+1):
fact=fact*i
print(fact)
print("factorial of",num,"is", fact)
Output:
Enter a number : 5
The factorial of 5 is : 120
[Link] calculate square root of number using
break and continue statement
import math
while(1):
num=(int (input("Enter no:")))
if (num==999):
break
elif (num<0): print("square root of negative
numbers cannot be calculated ")
continue
else:
print("square root of",num,"=",[Link](num))
Output:
Enter no : 64
square root of 64 = 8.0
Enter no : 999
[Link] Using function and return statement
def oddeven(a):
if (a%2==0):
return 1
else:
return -1
a=int(input("Enter the number:"))
float = oddeven(a)
if(float==1):
print("number is even")
else:
print("number is odd")
Output:
Enter the number: 10
Number is Even
[Link] using recurtion
def fibonacci(n):
if(n<2):
return 1
else:
return(fibonacci(n-1)+fibonacci(n+2))
n=int(input("Enter the terms of number:"))
for i in range(n):
print("fibonacci(",i,")=",fibonacci(i))
Output:
Enter the number of terms : 5
fibonacci (0) = 1
fibonacci (1) = 1
fibonacci (2) = 2
fibonacci (3) = 3
fibonacci (4) = 5
[Link] to reverse the vowels from a
given string
from array import*
abc=array ('i',[1,2,3,4,5])
[Link]()
print("Reverse item is:",abc)
Output:
Reversed item is : array('i', [4, 3, 2, 1])
[Link] to remove the vowels from a
given string
def remove_vowel(s):
new_str=" "
for i in s:
if i in "aeiouAEIOU":
pass
else:
new_str+=i
print("The string without the vowel
is:",new_str)
str=(input("Enter the string:"))
remove_vowel(str)
Output:
Enter a string : Pugal
The string without vowels is : pgl
[Link] to remove all the duplicates from a
list
a=[1,2,3,3,2,6]
dup_item=set()
uniq_item=[]
for x in a:
if x not in dup_item:
uniq_item.append(x)
dup_item.add(x)
print("The original list contains ... :",a)
print("the after removing the duplicate element,
unique item...:",dup_item)
Output:
The Original list contain……: [1, 2, 3, 3, 2, 6]
After removing the duplicate entries,
unique item are…… [1, 2, 3, 6]
[Link] to have a list with positive values
only
def is_positive(x):
if(x>=0):
return x
num_list=[10,-20,30,-40,50]
list=list(filter(is_positive,num_list))
print("positive integer value=",list)
Output:
Positive Values list = [10, 30, 50]
[Link] to create a dictionary
print("Enter -1 to exit")
circumference={}
while (1):
r=float(input("Enter radius:"))
if r==-1:
break
else:
dict={r:2*3.14*r}
[Link](dict)
print(circumference)
Output
Enter -1 to exit.....
Enter radius 9
Enter radius -1
{9.0 : 56.52 }