Flow of Control Book Programs
Flow of Control Book Programs
INPUT:
sum1 = sum2 = 0
numl = int(input("Enter number 1 : “)
num2 = int(input("Enter number 2 : “))
num3 = int(input("Enter number 3 " ) )
suml = numl + num2 + num3
if numl ! = num2 and numl ! = num3 :
sum 2 += num1
if num2 ! = numl and num2 ! = num3
sum2 += num2
if num3 != numl and num3 != num2
sum2 += num3
print ("Numbers are",numl, num2, num3)
print( "Sum of three given numbers is" , suml)
print("Sum of non-duplicate numbers is" , sum2)
import math
print(" For quadratic equation, ax**2+bx+c=0,enter coefficients below - ")
a = int(input("Enter a : "))
b = int(input("Enter b : "))
c = int(input("Enter c : "))
print("The Quadratic Equation is = ",a,'x^2 + ',b,'x + ',c,' = 0 ')
if a == 0:
print ("Value of",a, 'should not be zero')
print("\ n Aborting !!!!!!!")
else:
delta = b*b-4*a*c
if delta > 0 :
root1 = (-b+math.sqrt(delta))/(2*a)
root2 = (-b+math.sqrt(delta))/(2*a)
print("Roots are REAL and UNEQUAL")
print("Root 1 = ",root1,"Root 2 = ",root2)
elif delta == 0 :
root1 = -b/(2*a)
print("Roots are REAL and EQUAL")
print("Root 1 = ",root1,"Root 2 = ",root1)
else:
print("Roots are COMPLEX and IMAGINARY")
num = 5
for a in range (1,11):
print(num,’x’,a ‘=’ , num *a)
sum = 0
for n in range(1, 8) :
sum += n
print ("Sum of natural numbers <=",n, "is", sum)
sum = 0
for n in range(1, 8):
sum += n
print ("Sum of natural numbers n <=, 'is', sum)
Program 14 = Program to calculate factorial of a number
INPUT:
Program 15 =Program to calculate and print the sums of even and odd
integers of the first n natural numbers.
INPUT:
import random
number = random. randint(10, 50)
ctr = 0
while ctr < 5 :
guess = int(input( "Guess a number in range 10...........50 = "))
if guess == number :
print ("You win !!!")
break
else:
ctr+=1
if not ctr< 5 :
print("You lost : (\n the number was",number)