(Grade X) Chapter 4 : Programming in Python- Review

 



Part 1- Review of Basic Python

Introduction

·  Python is a high-level, general-purpose programming language used for many types of applications.

·  It was created by Guido van Rossum and first released in 1991.

·  Python is known for its simple and readable syntax, making it popular among beginners and professionals.

·  It is widely used in areas like web development, data science, automation, and artificial intelligence.

 

Input/output Statement

Syntax and exampleà Page number 137

 

Variables

·  Must start with a letter or underscore (_)
valid: name, _age
invalid: 1name

 

·  Cannot start with a number
age1
1age

 

·  Only letters, numbers, and underscores allowed
total_marks
total-marks, total marks

 

·  Case-sensitive
Name, name, and NAME are all different variables.

 

·  Cannot use Python keywords
class, if, for (these are reserved words)

 

·  No need to declare type
You can directly assign values:
x = 10, name = "Ram"

 

Sequential Program

1.     Write a program to display the sum of any two integer numbers given by the user.

x = int(input("First number:"))

y = int(input("Second number:"))

sum = x+y

print("The sum of two numbers is", sum)

 

2.     Write a program to display the average of three numbers.

a = float (input(" Enter the First Number:"))

b = float (input(" Enter the second number: "))

c = float (input(" Enter the third number: "))

avg=(a+b+c)/3

print("The average of three numbers is ", avg)

 

3.     Write a program to calculate the area of a circle.

r = float (input(" Enter the radius:"))

a =(22/7)* r * r

print("Area of the circle is”,a)

 

4.     Write a program to calculate the volume of a cylinder.

r = float (input(" Enter the radius:"))

h = float (input(" Enter the height: "))

v =(22/7)* r * r* h

print(f"Volume of the cylinder is {v}")

 

Page number 168 Lab sheet 1à 1,2,3

 

Conditional Program

1.      Write a program to display the greatest number among any two different numbers given by the user.

num1 = int(input("Enter the first number: "))

num2 = int(input("Enter the second number: "))

if num1 > num2:

print(f"The greatest number is {num1}")

else:

print(f"The greatest number is {num2}")

 

2.      Write a program to check whether the given number is divisible by 7 or not.

z = int(input("Enter the number: "))

if z% 7==0:

print("The number is divisible by 7")

else:

print("The number is not divisible by 7")

 

3.      Write a program to display the smallest number among any three numbers given by the user.

a = float(input("Enter the first number: "))

b = float(input("Enter the second number: "))

c = float(input("Enter the third number: "))

if a < b and a <c:

print(f"The smallest number is {a}")

elif b < a and b <c:

print(f"The smallest number is {b}")

else:

    print(f"The smallest number is {c}")

 

4.      Write a program to input the marks of three subjects of a student and display whether the student is pass or fail. (Assume that the pass marks of each subject is 35)

m1 = float(input("Enter the marks of first subject: "))

m2= float(input("Enter the marks of second subject: "))

m3 = float(input("Enter the marks of third subject: "))

if m1 >= 35 and m2 >= 35 and m3 >= 35:

print("The Student is Pass")

else:

print("The Student is Fail")

 

 

 

Page number 169 Lab sheet 1à 4,5,6 and 7

 

 

Looping Programs

 

1.Write a program to display all the numbers from 1 to 50.

for x in range(1, 51):

print(x, end=" ")

 

2.Write a program to display all the numbers from 1 to 50 using while loop.

a = 1

while a <= 50:

print(a, end=" ")

a=a+1

 

3. Write a program to display the following series.

a.1,4, 9, 16...........up to 10th terms

for i in range(1,11):

n =i * i

print(n, end= " ")

 

b. 1, 5 ,9 ,13.........up to 10th terms

x = 1

n = 1

while x <=10:

print(n, end= " ")

n = n + 4

x = x + 1

 

4. Write a program to display the sum of all the numbers from 1 to 20.

z = 1

s = 0

while z <= 20 :

s = s + z

z = z + 1

print("Sum of all the numbers from 1 to 20 is", s)

 

5. Write a program to display the factorial of the given number

p = 1

n=int(input("Enter a number: "))

for i in range(1, n + 1):

    p =p * i

print(f"The factorial of {n} is {p}")

 

6.Write a program to display the given number in reverse order.

n=int(input("Enter a number: "))

s=0

while n != 0:

    r = n%10

    s=s*10+r

    n =n//10

print("Reversed number is: ", s)

 

Page number 169 Lab sheet 1à 8,9,10,11,12,13,14,15 and 16

 

List and Dictionary

1. Write a program to display the even numbers from the list.

number = [100, 11, 4, 45, 54 ,93,200,65]

for n in number:

    if n % 2==0:

        print(n, end=" ")

 

2. Write a program to input ten numbers from the user and store them in the list.  The program should then display the greatest and smallest number.

num = []

for x in range(10):

    n = int(input('Enter number: '))

    num.append(n)

g = max(num)

s = min(num)

print(f"Greatest number in the list is {g}")

print(f"Smallest number in the list is {s}")

 

3. Write a program to store five numbers in the list. The program should display the sum and average of the numbers.

list = []

for i in range(5):

    n = int(input('Enter number'))

    list.append(n)

s = sum(list)

avg=s/5

print("Sum is = ",s)

print("Average = ", avg)

 

4. Write a program to store ten numbers in a list. The program should then count the even and odd numbers separately.

L=[]

even = 0

odd = 0

for i in range(10):

    n=int(input('Enter number: '))

    L.append(n)

for x in L:

    if x% 2==0:

        even += 1

    else:

        odd += 1

print("Even numbers in the list:", even)

print("Odd numbers in the list:", odd)

5. Write a program to check if the value 50 exists in the given dictionary.

data={"a": 25, "b": 20, "c": 300, "d": 50}

for i in data.values():

if i = 50:

print("50 is present in the dictionary")

 

Page number 169 Lab sheet 1à 17, 18 and 19

 

String Function

1. Write a program to count the number of characters present in the given word.

s=input("Enter the word::")

n=len(s)

print("Number of characters are",n)

 

2.Write a program to convert the given word into upper case.

s=input("Enter the word::")

u=s.upper()

print("The word in upper case is ",u)

 

3.Write a program to display the longest word among two different words.

x = input("Enter the first word: ")

y = input("Enter the second word: ")

a = len(x)

b = len(y)

if a > b:

    print(f"The longest word is {x}")

else:

    print(f"The longest word is {y}")

 

4. Write a program to count the number of vowels present in the given word

w = input("Enter the word: ")

c = 0

u = w.upper()

for i in u:

    if i == 'A' or i == 'E' or i == 'I' or i == 'O' or i == 'U':

        c = c + 1

print("Number of vowels =", c)

 

5. Write a program to display the given word in reverse order.

s = input("Enter the word: ")

rev = ""

for i in s:

    rev = i + rev

print(f"Reverse of the word is {rev}")

 

6. Write a program to display whether the given word is palindrome or not.

x = input("Enter the word: ")

r = ""

for i in x:

    r = i + r

if r == x:

    print("The word is palindrome")

else:

    print("The word is not palindrome")

Page number 169 Lab sheet 1à 20, 21 and 22