Sindhi High School Python
Sindhi High School Python
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)
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)
#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)
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)