addition of complex numbers
a=int(input("enter a number"))
b=int(input("enter a number"))
c=complex(a,b)
x=int(input("enter a number"))
y=int(input("enter a number"))
d=complex(x,y)
print("real values are ",c.real,d.real)
print("imaginary values are ",c.imag,d.imag)
print(c.real,"+",c.imag,"j")
Roots of a quadratic equation
from math import *
a=int(input("enter a value"))
b=int(input("enter b value"))
c=int(input("enter c value"))
d=b**2-4*a*c
r1=[-b+sqrt(d)]//2
r2=[-b+sqrt(d)]//2
print("roots are",r1,r2)
Biggest of three numbers using nested
if-else
a=int(input("enter 1st num"))
b=int(input("enter 2nd num"))
c=int(input("enter 3rd num"))
if(a>b):
if(a>c):
print("a is big")
else:
print("c is big")
else:
if(b>c):
print("b is big")
else:
print("c is big")
Biggest of two numbers using if-else
a=int(input("enter a number"))
b=int(input("enter a number"))
if a>b:
print(a," is big")
if a<b:
print(b," is big")
program to check number is positive or
negitive or zero
a=int(input("enter a value"))
if a>0:
print("+ve num")
elif a<0:
print("-ve num")
else:
print("num is Zero")
calculator program
print('well come to calculator')
answer = str(input('what do you want to do? multiplication,division,addition or substraction '))
if answer == 'multiplication':
a=int(input('enter any integer number'))
b=int(input('enter any integer number'))
c=a*b
print('the product of the 2 numbers is', c)
if answer == 'division':
a=int(input('enter any integer number'))
b=int(input('enter any integer number'))
c=a/b
print('the outcome of the 2 numbers is', c)
if answer == 'addition':
a=int(input('enter any integer number'))
b=int(input('enter any integer number'))
c=a+b
print('the sum of the 2 numbers is', c)
else:
a=int(input('enter any integer number'))
b=int(input('enter any integer number'))
c=a-b
print('the difference between the 2 numbers is', c)
Student marks and grade with average
s1=int(input("enter first subject marks"))
s2=int(input("enter second subject marks"))
s3=int(input("enter third subject marks"))
s4=int(input("enter fourth subject marks"))
tot=s1+s2+s3+s4
avg=tot/4
if avg>=70:
print("grade A with ",avg)
elif avg>=60:
print("grade B with ", avg)
elif avg>=50:
print("grade C with ", avg)
elif avg>=40:
print("grade D with ", avg)
else:
print("FAIL with ",avg)
Biggest of three numbers using elif
x=int(input("enter first number"))
y=int(input("enter second number"))
z=int(input("enter third number"))
if x>y and x>z:
print(x," is biggest number among ",y," and ",z)
elif y>z:
print(y," is biggest number among ",x," and ",z)
else:
print(z," is biggest number among ",y," and ",x)
Program to check given character is
vowel or consonant
x=str(input("enter a letter"))
if x=='a' or x=='e' or x=='i' or x=='o' or x=='u'or x=='A' or x=='E' or x=='I' or x=='O' or x=='U':
print("given letter is vowel")
else:
print("given letter is consonant")
leap year or not program
year=int(input("enter any year"))
if(year%4==0 or year%400==0)or (year%100!=0):
print("leap year")
else:
print("not a leap year")
find factors of given number
num=int(input("enter a number"))
i=1
while i<=num:
if num%i==0:
print(i,end=" ")
i=i+1
to check given number is prime or not
program1:
num=int(input("enter a number"))
i=1
count_fact=0
while i<=num:
if num%i==0:
count_fact=count_fact+1
i=i+1
if count_fact==2:
print("prime number")
else:
print("not prime number")
program 2:
num=int(input("enter a number"))
i=2
while i<=num//2:
if num%i==0:
print("not prime number")
break
i=i+1
else:
print("number is prime number")
triangle pattern printing
*
**
***
****
*****
row=int(input("enter no.of rows"))
for i in range(row):
for j in range(i+1):
print("*",end=" ")
print("")
**
***
****
*****
row=int(input("enter no.of rows"))
for i in range(row):
for j in range(row):
if row-i-1>j:
print(" ",end=" ")
else:
print("*",end=" ")
print("")
sum of digits
num=int(input("enter a number"))
sum=0
rev=0
while num!=0:
rem=num%10
sum=sum+rem
num=num//10
print("sum of digits is ",sum)
swaping
a=int(input("enter a value"))
b=int(input("enter b value"))
a,b=b,a
print("after swaping")
print("a=",a,"b=",b)
fibonacii series of numbers
num1=int(input("enter a number"))
num2=int(input("enter a number"))
le=int(input("enter the length of series"))
i=1
while i<=le:
n=num1+num2
print(n,end=" ")
num1=num2
num2=n
i=i+1