0% found this document useful (0 votes)
34 views

Sindhi High School Python

The document provides examples of Python programs to solve problems involving basic mathematical and logical operations. It includes programs to calculate areas and volumes, sort numbers, check conditions, and iterate through loops. A variety of problems are presented to demonstrate Python syntax and basic programming concepts.

Uploaded by

Test
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Sindhi High School Python

The document provides examples of Python programs to solve problems involving basic mathematical and logical operations. It includes programs to calculate areas and volumes, sort numbers, check conditions, and iterate through loops. A variety of problems are presented to demonstrate Python syntax and basic programming concepts.

Uploaded by

Test
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

INTRODUCTION TO PYTHON

Q1)Write a program to display your name, class and school


print("Vishnu")
print("11 A")
print("SHS")
Q2) Write a program to find area and of a rectangle whose length is 4 units and
breadth is 6 units.
l=3
b=6
area=l*b
print(f"Area is {area}”)
Q3) Write a program to find area of perimeter of a circle with the radius as 5
units.
radius=5
pi=22/7
areacircle=pi*radius*radius
circumference=2*pi*radius
print("Area of circle is", areacircle)
print("Circumference of circle is", circumference)

Q4)Write a program to compute simple interest.


p=int(input("Enter Principle"))
t=int(input("Enter time period"))
r=int(input("Enter Rate"))
si=(p*t*r)/100
print("The simple Interest is", si)
Q5) Write a program to accept the side of a square from the user and display
the area and perimeter.
a=int(input("Enter side of square"))
Area=a*a
Perimeter=4*a
print("area of square is", Area)
print("Perimeter of square is", Perimeter)
Q6) Write a program to accept the length and breadth of a rectangle and
calculate and display area and perimeter.
L=int(input("Enter length of rectangle"))
B=int(input("Enter breadth of rectangle"))
AREA=L*B
PERIMETER=2*(L+B)
print("PERIMETER of rectangle is", PERIMETER)
print("AREA of rectangle is", AREA)
Q7) Write a program to find the area of a triangle.
base=int(input("Enter length if base of triangle"))
height=int(input("Enter height of triangle"))
Area=0.5*base*height
print("area of triangle is”, Area)
Example Theory
num1=int(input("Enter Number 1"))
num2=int(input("Enter Number "))
num3("Result =",num3)
Q8) Write a program to enter length and breadth and calculate area of
rectangle
L=int(input("Enter length of rectangle"))
B=int(input("Enter breadth of rectangle"))
area
print("Area of rectangle is", area)

Q9) Write a program to enter radius of circle and calculate area of circle
radius=int(input("Enter the radius of the circle"))
pi=22/7
area=pi*r*r
print("Area of the circle is", area)
Q10) Write a program to enter Name, marks of 5 subject and calculate total &
percentage of student
Name=str(input("Enter name"))
maximum=int(input("Enter maximum marks of each subject"))
num1=float(input("Enter Physics marks"))
num2=float(input("Enter Chemistry marks"))
num3=float(input("Enter Maths marks"))
num4=float(input("Enter Computer marks"))
num5=float(input("Enter English marks"))
TOT=num1+num2+num3+num4+num5
avg=TOT/5
print("Total marks of",Name,"is",TOT)
print("Average marks of",Name,"is",avg)

Q11) Write a program to enter distance in feet and convert it into inches
dis=float(input("Enter distance in feet"))
inch=dis*12
print("Distance in inches is", inch,"inches")
Q12) Write a program to enter value of temperature in Fahrenheit and convert
it into Celsius.
cel=float(input("Enter temperature in Celsius"))
far=(cel*(9/5))+32
print("Temperature in Fahrenheit is”, far)
Q13) Write a program to enter radius and height of cylinder and calculate
volume of cylinder.
rad=float(input("Enter radius of cylinder"))
hei=(float(input("Enter height of cylinder"))
pi=22/7
vol=pi*rad*rad*hei
print("volume of cylinder is", vol)

Q14)Write a program to find reverse of a two digit number.


a=int(input("Enter a two digit number"))
b=int(a/10)
c=int(a-(10*b))
print(c,b,sep= "")
OR
x=int(input("enter a two digit no."))
a=x%10
b=(x-a)//10
print(a*10+b)
Q16) Write a program to calculate square root of a number.
num1=int(input("Enter a number"))
num2=num1**(1/2)
print("Square root of the number is",num2)

Q17)Write a program to swap two values of two variables.


x=int(input("Enter a number x"))
y=int(input("Enter another number y"))
x,y=y,x
print("x is",x)
print("y is",y)
Q15)WAP to reverse the digits of a number
n=int(input('enter a number'))
num=n
rev=0
while n>0:
dig=n %10
rev=rev*10+dig
n=n//10
print(rev)

FLOW OF CONTROL
Q1) WAP to accept age from the user and check if the person is eligible to vote
or not.
age = int(input("Enter your age : "))
if age>= 18 :
print("Your age is", age)
print("You are eligible to vote")
else :
print("You are not eligible to vote")
Q2) WAP to accept a percentage from the user and display whether the
student has passed or failed in the test.
percentage = int(input("Enter your percentage : "))
if percentage >= 50 :
print("Your percentage =", percentage)
print("You have passed")
else :
print("Your percentage =", percentage)
print("Unfortunately, you have not passed")
Q3) WAP to accept two numbers and display the maximum of the two
numbers.
a = int(input("Enter the first number : "))
b = int(input("Enter the second number : "))
if a>b :
print("The greater number is :", a)
else :
print("The greater number is :", b)
Q4) WAP to accept the temperature either in Fahrenheit or Celsius and convert
it to the other form.
t = int(input(“Enter your temperature in F or C ”)
c = ((t – 32)*5)/9
F = ((t*9)/5) + 32
fc = input(“Do you want to convert to F or C?”)
if fc == “F”:
print(f’Temperature in F = {F}’)
else:
print(f’Temperature in C = {C}’)

Q5) WAP to input monthly sales of an employee and give a bonus of 10% if sale
is more than 50,000 , otherwise bonus will not be given. Print appropriate
messages
a = int(input("Enter monthly sales : "))
if a > 50000 :
b = a + (1/10)*a
print("A bonus of", (1/10)*a, "has been granted to you based on your sales")
else :
print("You did not meet the target. No bonus has been granted")
Q6) WAP to check if a number is positive or negative.
a = int(input("Enter a number : "))
if a > 0 :
print("The number is positive")
elif a < 0 :
print("The number is negative")
else :
print("It is neither positive nor negative. It is zero.")
Q7) WAP to check if the number entered is even or odd.
a = int(input("Enter a number : "))
x = a%2
if x == 0 :
print("It is even")
else :
print("It is odd")
Q8) WAP to accept 3 numbers and print the smallest of the three numbers.
a = int(input("Enter the first number : "))
b = int(input("Enter the second number : "))
c = int(input("Enter the third number : "))
print("The smallest number is")
if a<b and a<c :
print(a)
if b<a and b<c :
print(b)
if c<a and c<b :
print(c)

Q9) WAP to accept the marks and print the grade obtained based on the given
data
85 – 100 = A
60 – 84 = B
40 – 59 = C
30 – 39 = D
<30 = F(Fail)
m = int(input("Enter your marks (out of 100) : "))
if m >= 85 and m <= 100 :
print("Grade = A")
if m >= 60 and m < 85 :
print("Grade = B")
if m >= 40 and m < 60 :
print("Grade = C")
if m >= 30 and m < 40 :
print("Grade = D")
if m < 30 :
print("Grade = F (fail)")
Q10) WAP to check if the year is a leap year or not.
Year = int(input(“Enter any year”))
If year % 100 == 0 :
If year % 400 == 0:
print(“Year is a leap year “)
else :
print(“Year is not a leap year “)
elif year % 4 == 0 :
print(“Year is a leap year”)
else :
print(“Year is not a leap year”)
Q11) Program to input three numbers and print them in ascending order.
x = int(input(“Enter the first number : “))
y = int(input(“Enter the second number : “))
z = int(input(“Enter the third number : “))
if y >= x <= z :
if y <= z :
min, mid, max = x,y,z
else :
min, mid, max = y,z,x
elif x>= y <= z :
if x <= z :
min, mid, max = y,x,z
else :
min, mid, max = z,y,x
elif x >= z <= y :
if x <= y :
min, mid, max = z,x,y
else :
min, mid, max = z,y,x
print(“Numbers in ascending order =”, min, mid, max)
Q12) Program to check whether any word is a part of a sentence or not.
line = input(“Enter any statement”)
word = input(“Enter any word”)
if word in line :
print(“Yes”, word,, “is a part of”, line)
else :
print(“No”, word, “is not a part of”, line)
Q13)WAP to enter generate numbers from 0 to 10 using range function and for
loop.
for i in range (0,11) :

print(i)
Q14) WAP to enter any character and print whether it is in upper, lower case,
digit or symbol.
Q15) WAP to print multiplication tables of a given number.
x = int(input("Enter any number : "))
for a in range(1,11) :
print(a*x)
Q16) WAP to print the sum of first 100 natural numbers.
sum = 0
for x in range(1,101) :
sum+= x
print(sum)
Q17) WAP to enter marks in 5 subjects and calculate the total, percentage and
division.
a = int(input("Enter marks obtained in English : "))
b = int(input("Enter marks obtained in Hindi : "))
c = int(input("Enter marks obtained in Maths : "))
d = int(input("Enter marks obtained in Science : "))
e = int(input("Enter marks obtained in Social Science : "))
total = a + b + c + d + e
print("Total =", total)
percentage = total / 5
print("Percentage =", percentage)
Q18) WAP to print the first 10 natural numbers using while loop
num = 1
while num <= 10 :
print(num)
num = num+1
Q19) WAP to print the multiplication table of any given number using while
loop
i=1
a = int(input("Enter a number"))
while i <= 10 :
print(a, "x", i, "=", a*i)
i = i+1
Q20) WAP To print the sum of the first 100 natural numbers using while loop
i=0
a=i
while i <= 100 :
a=a+i
i=i+1
print(a)
Q21) WAP to find the sum of all numbers divisible by 7 from 1 to 100
a=1
b=0
while a <= 100 :
if a%7 == 0 :
b=a+b
a += 1
print("Sum of all numbers between 1 and 100 which are divisible by 7 =", b)
Q22) WAP to enter any number and find it's factorial
num = int(input("Enter a number : "))
i=1
a=1
while i <= num :
a = a*i
i += 1
print("Factorial of", num, "=", a)
Q23) WAP to print a Fibonacci series up to n terms
n = int(input("Enter the number of terms : "))
i=1
print("The Fibonacci series up to n terms =")
a=0
b=1
print(a)
print(b)
while i <= n :
c=a+b
a=b
b=c
print(c)
i += 1
Q24) WAP to enter 10 numbers and find their sum and average
i=1
sum = 0
while i <= 10 :
print("Enter the", i, ” number")
a = int(input())
sum += a
i = i+1
print("Sum of the numbers =", sum)
print("Average =", sum/10)
Q25) WAP To enter the Lower Limit, Upper Limit and find the sum of all odd
and even numbers between the range separately
Lower_Limit = int(input("Enter the lower limit : "))
Upper_Limit = int(input("Enter the upper limit : "))
range = (Upper_Limit+1) - Lower_Limit
i=1
odd = 0
even = 0
while i <= range :
if Lower_Limit % 2 == 0 :
even += Lower_Limit
else :
odd += Lower_Limit
Lower_Limit += 1
i += 1
print("Sum of all even numbers in this range =", even)
print("Sum of all odd numbers in this range=", odd)
Q26) WAP to enter any number and a digit and count how many times the digit
is in the number
num = input("Enter a number : ")
l = len(num)
i=0
t=0
a = input("Enter the digit which is to be counted : ")
while i <= l :
if num[i] == a :
t += 1
i += 1
else :
t=t
print("The number of times", a, "occurs is", t)

WAP to enter a number and find it's reverse


num = int(input("Enter a number : "))
rev = 0
i = num
while i > 0 :
r = i%10
rev = rev*10 + r
i = i//10
print("Original number =", num)
print("Reverse =", rev)
Q27) WAP to enter a number repeatedly and print the sum. The program
terminates when the user says no more to enter (normal termination) or the
program aborts when the number entered is less than 0.
sum = 0
a=1
num = 0
prev = 0
while a == 1 :
num = int(input("Enter a number : "))
if num < 0 :
print("Number entered is less than 0. Aborting! ")
break
else :
sum += num
min = num
if num > prev :
max = num
prev = num
else :
max = prev
if num <= min :
min = num
a = int(input("To continue the program, press '1'. Otherwise, press '0'"))
print("Sum of numbers =", sum)
print("Highest number =", max)
print("Lowest number =", min)
Q28) WAP to input a number and test if it is prime or not
num = int(input("Enter a number : "))
n = num//2 + 1
for i in range(2,n) :
if num % i == 0 :
print(num, "is not a prime number")
break
else :
print(num, "is a prime number")

Q29) WAP to check if Armstrong number or not


number = int(input("Enter your number: "))
original_number = number
sum_total = 0
if 99 < number > 1000:
while number > 0:
sum_total +=((number%10)**3)
number = number//10
if sum_total == original_number:
print("Its an Armstrong number")
else:
print("NO its not an Armstrong number")
if 999 < number > 10000:
while number > 0:
sum_total +=((number%10)**4)
number = number//10
if sum_total == original_number:
print("Its an Armstrong number")
else:
print("NO its not an Armstrong number")
else:
print("Error")

30 PROGRAMS FROM 9.1


#1)Program that takes a number and checks whether the number is odd or
even.
num=int(input("Entera any number"))
if num%2==0:
print("It is even")
else:
print("It is odd")

#2)Program to accept three integers and print the largest


x=y=z=0
x=float(input("Enter first number"))
y=float(input("Enter second number"))
z=float(input("Enter third number"))
maximum=x
if y>maximum:
maximum=y
if z>maximum:
maximum=z
print("Largest number is",maximum

#3)Program that inputs three numbers and calculates two sums as per this:
#Sum1 as the sum of all input numbers
#Sum2 as the sum of non duplicate numbers;if there are duplicate numbers in
the input, ignores them
sum1=sum2=0
num1=int(input("Enter first number"))
num2=int(input("Enter second number"))
num3=int(input("Enter third number"))
sum1=num1+num2+num3
if num1 != num2 and num1 != num3:
sum2 += num1
if num2 != num2 and num2 != num3:
sum2 += num2
if num3 != num2 and num3 != num2:
sum2 += num3
print("Numbers are", num1, num2, num3)
print("Sum of three given numbers is",sum1)
print("Sum of non duplicate numbers is",sum2)

#4)Program to test the divisibility of a number with another number


num1=int(input("Enter first number"))
num2=int(input("Enter first number"))
rem=num1%num2
if rem==0:
print("First number is divisible by second")
else:
print("First number not divisible by second")

#5)Program to find the multiples of a number out of given five numbers


num1=float(input("Enter first number"))
num2=float(input("Enter second number"))
num3=float(input("Enter third number"))
num4=float(input("Enter fourth number"))
num5=float(input("Enter fifth number"))
div=float(input("Enter the divisor"))
count=0
print("Multiiples of",div,"are:")
remainder=num=1%div
if remainder==0:
print(num1, sep="")
count +=1
remainder=num2%div
if remainder==0:
print(num2,sep="")
count +=1
remainder=num3%div
if remainder==0:
print(num3,sep="")
count +=1
remainder=num4%div
if remainder==0:
print(num4,sep="")
count +=1
remainder=num5%div
if remainder==0:
print(num5,sep="")
count +=1
print()
print(count,"multiples of",div,"found")

#6)Program to display a menu for calculating area of a circle or perimeter of a


circle.
r=float(input("Enter radius of the circle"))
print("1. Calculate Area")
print("2. Calculate Perimeter")
choice=int(input("Enter 1 for Area and 2 for Perimeter"))
if choice==1 :
a=(22/7)*r*r
print("Area of circle is”, a)
else:
p=(22/7)*2*r
print("Perimeter of circle is",p)
#7) Program that needs 2 numbers and an arithmetic operator and displays the
computed result.
num1=float(input(“Enter first number”))
num2=float(input(“Enter second number”))
op=input(“Enter operator [+ - * / %] :”)
result=0
if op==’+’:
result=num1+num2
elif op==’-’:
result=num1-num2
elif op==’*’:
result=num1*num2
elif op==’/’:
result=num1/num2
elif op==’%’:
result=num1%num2
else:
print(“Invalid operator !!”
print(num1, op, num2, ‘=’, result)
#8)Program that reads three numbers and prints them in ascending order
x=int(input(“Enter first number”))
y=int(input(“Enter second number”))
z=int(input(“Enter third number”))
min=mid=max=None
if x<y and x<z:
if y<z:
min, mid, max=x,y,z
else:
min, mid, max=x,z,y
elif y<x and y<z:
if x<z:
min, mid, max=y,x,z
else:
min, mid, max=y,z,x
else:
if x<y:
min, mid, max=z,x,y
else:
min, mid, max=z,y,x
print(“Numbers in ascending order :”,min, mid,max)
#9)Program to print whether a given character is an uppercase or a lowercase
character or a digit or any other character.
ch=input(“Enter a single character:”)
if ch>=’A’ and ch<=’Z’:
print(“You entered an Upper case character.”)
elif ch>=’a’ and ch<=’z’ :
print(“You entered a lower case character.”)
elif ch>=’0’ and ch<= ‘9’:
print(“You entered a digit.”)
else:
print(“You entered a special character.”)
#10) Program to calculate and print roots of a quadratic equation : ax 2+bx+c=0.
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:”))
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(“Root1=”, root1, “, Root2=”, root2)
elif delta==0:
root1=-b/(2*a);
print(“Roots are REAL and EQUAL”)
print(“Root1=”, root1, “, Root2=”, root1)
else:
print(“Roots are COMPLEX and IMAGINARY”)
#11)Program to print table of a number, say 5
Num=5
for a in range(1,11):
print(num, ‘x’, am ‘=’, num*a)
#12)Program to print sum of natural numbers between 1 to 7. Print the sum
progressively.
Sum=0
for n in range(1,8):
sum+=n
print(“Sum of natural numbers <=”, n, ‘is’, sum)

STRING MANIPULATION
1)WAP to read string and print it in reverse order
string1=input(“Enter any string”)
reverse = string1[len(string):-len(string)-1:-1)
print(reverse)
2)WAP to input string and print short form
String=input(“Enter any string”)
print(string[0],”.”,end=’’)
for ch in range
3)WAP to input any string and count how many vowels in the string
METHOD 1
str1=input(“Enter any string”)
count=
for s in str1:
if s==’a’ or s==’e’ or s==’I’ or s==’o’ or s==’u’:
count+=1
print(“Total Vowels occurs are”,count)
METHOD 2
Str1=input(“Enter any String”)
Vowels=[‘a’,’e’,’i’,’o’,’u’]
Count=0
for s in str1:
if s in vowels:
count+=1
print(“Total vowels occurs are”,count)

You might also like