0% found this document useful (0 votes)
40 views22 pages

204-PS - Practical Sheet With Solution Unit 1-2-3

Uploaded by

hns mrityunjay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views22 pages

204-PS - Practical Sheet With Solution Unit 1-2-3

Uploaded by

hns mrityunjay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

A.

Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
Unit-1- C Programming Practical sheet
Multidimensional Numeric & String Array
1. Write C program to calculate Addition of two Matrices.
/*Addition of two matrix in C */
#include<stdio.h>
#include<conio.h>
int main()
{
int a[3][3],b[3][3],sum[3][3],i,j;
clrscr();
printf("Enter Matrix A Elements: ");
for(i=0;i<3;i++)// rows
{
for(j=0;j<3;j++) //cols
{
printf("\n Enter Array element A[%d][%d] :",i,j);
scanf("%d",&a[i][j]);
}
}
printf("Enter Matrix B Elements: ");
for(i=0;i<3;i++) // rows
{
for(j=0;j<3;j++) //cols
{
printf("\n Enter Array element B[%d][%d] :",i,j);
scanf("%d",&b[i][j]);
}
}
printf("\n Matrix A : \n");
printf("~~~~~~~~~~~~~~~~~~~\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
printf("\n Matrix B : \n");
printf("~~~~~~~~~~~~~~~~~~~\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(" %d ",b[i][j]);
}
printf("\n");
}
printf("\n Sum of two matrices : \n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
for(i=0;i<3;i++)

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 1


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
{
for(j=0;j<3;j++)
{
sum[i][j]=a[i][j]+b[i][j];
printf("%d\t",sum[i][j]);
}
printf("\n");
}
getch(); return 0;
}

2. Write C program to calculate Subtraction of two Matrices.


/* Subtraction of two matrix in C */
#include<stdio.h>
#include<conio.h>
int main()
{
int a[3][3],b[3][3],sub[3][3],i,j;
clrscr();
printf("Enter Matrix A Elements: ");
for(i=0;i<3;i++)// rows
{
for(j=0;j<3;j++) //cols
{
printf("\n Enter Array element A[%d][%d] :",i,j);
scanf("%d",&a[i][j]);
}
}
printf("Enter Matrix B Elements: ");
for(i=0;i<3;i++) // rows
{
for(j=0;j<3;j++) //cols
{
printf("\n Enter Array element B[%d][%d] :",i,j);
scanf("%d",&b[i][j]);
}
}
printf("\n Matrix A : \n");
printf("~~~~~~~~~~~~~~~~~~~\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
printf("\n Matrix B : \n");
printf("~~~~~~~~~~~~~~~~~~~\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(" %d ",b[i][j]);
}
printf("\n");

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 2


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
}
printf("\n Subtraction of two matrices : \n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
sub[i][j]=a[i][j]-b[i][j];
printf("%d\t",sub[i][j]);
}
printf("\n");
}
getch(); return 0;
}

3. Write C program to calculate Multiplication of two Matrices.


#include<stdio.h>
#include<conio.h>
int main()
{
int a[3][3],b[3][3],mul[3][3],i,j,k;
clrscr();
printf("Enter Matrix A Elements: ");
for(i=0;i<3;i++)// rows
{
for(j=0;j<3;j++) //cols
{
printf("\n Enter Array element A[%d][%d] :",i,j);
scanf("%d",&a[i][j]);
}
}
printf("Enter Matrix B Elements: ");
for(i=0;i<3;i++) // rows
{
for(j=0;j<3;j++) //cols
{
printf("\n Enter Array element B[%d][%d] :",i,j);
scanf("%d",&b[i][j]);
}
}
printf("\n Matrix A : \n");
printf("~~~~~~~~~~~~~~~~~~~\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
printf("\n Matrix B : \n");
printf("~~~~~~~~~~~~~~~~~~~\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(" %d ",b[i][j]);
}

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 3


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
printf("\n");
}
for (i = 0; i < 3;i++)
{
for (j = 0; j < 3; j++)
{
mul[i][j] = 0;
for (k = 0; k < 3; k++)
{
mul[i][j] = mul[i][j] + (a[i][k] * b[k][j] );
}
}
}
printf("\nMultiplication of Matrices : \n");
for(i=0;i < 3;i++)
{
for(j=0;j < 3;j++)
{
printf("%d\t", mul[i][j]);
}
printf("\n");
}
getch();return 0;
}

4. Write C program to Transpose of Single Matrix.


/* C program to find transpose of 3 X 3 matrix */
#include<stdio.h>
#include<conio.h>
int main()
{
int a[3][3],i,j;
clrscr();
printf("Enter Matrix A Elements: ");
for(i=0;i<3;i++)// rows
{
for(j=0;j<3;j++) //cols
{
printf("\n Enter Array element A[%d][%d] :",i,j);
scanf("%d",&a[i][j]);
}
}
printf("\n Matrix A : \n");
printf("~~~~~~~~~~~~~~~~~~~\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("\n Transpose of matrix A : \n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 4


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
{
printf("%d\t",a[j][i]);
}
printf("\n");
}
getch(); return 0;
}

5. Write C program to count total duplicate elements in an array.


#include <stdio.h>
#include<conio.h>

int main()
{
int arr[10];
int n, mm = 1, ctr = 0;
int i, j;

printf("Input the number of elements to be stored in the array :");


scanf("%d", &n);

printf("Input %d elements in the array :\n", n);


for (i = 0; i < n; i++)
{
printf("element - %d : ", i);
scanf("%d", &arr[i]);
}
// Check for duplicate elements in the array using nested loops
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
if (arr[i] == arr[j])
{
ctr++;
break; // Exit the inner loop as soon as a duplicate is found
}
}
}

printf("Total number of duplicate elements found in the array: %d\n", ctr);


return 0;
}

6. Write C program to find sum of each row and column of a matrix.

#include <stdio.h>
#include<conio.h>

#define SIZE 3

int main()
{
int A[SIZE][SIZE];
int row, col, sum = 0;

/* Input elements in matrix from user */


printf("Enter elements in matrix of size %dx%d: \n", SIZE, SIZE);

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 5


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
for(row=0; row<SIZE; row++)
{
for(col=0; col<SIZE; col++)
{
scanf("%d", &A[row][col]);
}
}

/* Calculate sum of elements of each row of matrix */


for(row=0; row<SIZE; row++)
{
sum = 0;
for(col=0; col<SIZE; col++)
{
sum += A[row][col];
}

printf("Sum of elements of Row %d = %d\n", row+1, sum);


}

/* Find sum of elements of each columns of matrix */


for(row=0; row<SIZE; row++)
{
sum = 0;
for(col=0; col<SIZE; col++)
{
sum += A[col][row];
}
printf("Sum of elements of Column %d = %d\n", row+1, sum);
}
getch(); return 0;
}

To get 10 String from User and Display it.


#include<stdio.h>
#include<conio.h>

void main()
{
char text[10][80];
int i,n;
clrscr();

printf(" Enter N Strings(out of 10): ");


scanf("%d",&n);

flushall();
for(i = 0; i < n ; i++)
{
printf("\n Enter Some string for index %d: ", i + 1);
gets(text[i]);
}

for(i = 0; i < n; i++)


{

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 6


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
printf("\n Some string for index %d: ", i + 1);
puts(text[i]);
}

getch();
}

Write a program to sort elements in lexicographical order in C language (dictionary order).


#include<stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
char str[10][50],temp[50];
int i,j,n;
clrscr();

printf("Enter N string(out of 10) :");


scanf("%d",&n);

printf("Enter Words:\n");
for(i=0;i<n;i++)
{
printf("\n Enter String %d : ",i+1);
scanf("%s[^\n]",str[i]);
}
for(i=0;i < n-1;i++)
{
for(j=i+1;j < n;j++)
{
if(strcmp(str[i],str[j]) > 0)
{
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
}
}
}
printf("\nIn Lexicographical order: \n");
for(i=0;i < n;i++)
puts(str[i]);

getch();
return 0;
}

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 7


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
User defined Function
1. Write C Program to find area of rectangle using User defined Function.
#include <stdio.h>
#include<conio.h>

int area(int length, int width)


{
return length * width;
}
int main()
{
int length, width, calarea;
printf("Enter the length of the rectangle: ");
scanf("%d", &length);
printf("Enter the width of the rectangle: ");
scanf("%d", &width);
calarea = area(length, width);
printf("The area of the rectangle is: %d\n", calarea);
getch(); return 0;
}

2. Write C Program to find perimeter of rectangle using User defined Function.


#include <stdio.h>
#include<conio.h>
int perimeter(int length, int width)
{
return 2 * (length + width);
}
int main()
{
int length, width, perimeter;

printf("Enter the length of the rectangle: ");


scanf("%d", &length);

printf("Enter the width of the rectangle: ");


scanf("%d", &width);

perimeter = perimeter(length, width);

printf("The perimeter of the rectangle is: %d\n", perimeter);

getch(); return 0;
}

3. Write C Program to find diameter, circumference and area of circle using User defined
Function.
#include <stdio.h>
#include<conio.h>
#include <math.h>

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 8


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills

// User-defined function to calculate the diameter of a circle


float calculateDiameter(float radius) {
return 2 * radius;
}

// User-defined function to calculate the circumference of a circle


float calculateCircumference(float radius) {
return 2 * M_PI * radius;
}

// User-defined function to calculate the area of a circle


float calculateArea(float radius) {
return M_PI * radius * radius;
}

int main() {
// Declare variables
float radius, diameter, circumference, area;

// Get the radius of the circle from the user


printf("Enter the radius of the circle: ");
scanf("%f", &radius);

// Calculate the diameter, circumference, and area of the circle


diameter = calculateDiameter(radius);
circumference = calculateCircumference(radius);
area = calculateArea(radius);

// Print the results


printf("The diameter of the circle is: %.2f\n", diameter);
printf("The circumference of the circle is: %.2f\n", circumference);
printf("The area of the circle is: %.2f\n", area);

return 0;
}

4. Write C program to convert centimeter to meter and kilometer using User defined
Function.
#include <stdio.h>
#include<conio.h>

float cm_to_meter(float cm) {


return cm / 100.0;
}

float cm_to_kilometer(float cm) {


return cm / 100000.0;
}

int main() {

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 9


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
float cm, meter, km;

printf("Enter length in centimeter: ");


scanf("%f", &cm);

meter = cm_to_meter(cm);
km = cm_to_kilometer(cm);

printf("Length in meter = %.2f m\n", meter);


printf("Length in kilometer = %.2f km\n", km);

return 0;
}

5. Write C program to convert temperature from degree Celsius to Fahrenheit using UDF.
#include <stdio.h>
#include<conio.h>

float celsiusToFahrenheit(float celsius)


{
return (celsius * 9 / 5) + 32;
}

int main()
{
float celsius, fahrenheit;
printf("Enter the temperature in Celsius: ");
scanf("%f", &celsius);
fahrenheit = celsiusToFahrenheit(celsius);
printf("The temperature in Fahrenheit is: %f\n", fahrenheit);
return 0;
}

6. Write C Program to find Sum of Series 1²+2²+3²+…..+n² Using Recursion in C.


/* C Program to Calculate Sum of series 1²+2²+3²+....+n² */
#include <stdio.h>

int main()
{
int Number, Sum = 0;

printf("\n Please Enter any positive integer \n");


scanf(" %d",&Number);

Sum = (Number * (Number + 1) * (2 * Number + 1 )) / 6;

printf("\n The Sum of Series for %d = %d ",Number, Sum);

}
Explanation
In the next line, We are calculating the Sum of the series 1²+2²+3²+4²+5² using above formula

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 10


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
Sum = (Number * (Number + 1) * (2 * Number + 1 )) / 6;
Sum = (5 * (5 + 1) * (2 * 5 +1)) / 6
Sum = (5 * 6 * 11) / 6
Sum = 330 /6
Sum = 55

The C Program to Find Sum of series 1²+2²+3²+….+n² final output for 5 = 55

7. Write C Program to find maximum and minimum element in array using UDF.
#include<stdio.h>
#include<conio.h>

int findmaxmin(int a[],int n)


{
int min,max,i;
min=max=a[0];
for(i=1; i<n; i++)
{
if(min>a[i])
min=a[i];
if(max<a[i])
max=a[i];
}

printf("\n minimum of array is : %d",min);


printf("\n maximum of array is : %d",max);
}
int main()
{
int a[100],i,n,sum;
clrscr();

printf("Enter size of the array : ");


scanf("%d", &n);

printf("Enter elements in array : ");


for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
findmaxmin(a,n);

getch();
return 0;
}

Structure programme

1. Write a C program that creates structure of an array of structures that stores information
of 5 students and prints it.
#include<stdio.h>
#include<string.h>
#include<conio.h>
struct student
{
int rollno;

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 11


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
char name[10];
};
int main()
{
int i;
struct student st[5];
clrscr();
printf("Enter Records of 5 students");
for(i=0;i<5;i++)
{
printf("\nEnter Rollno:");
scanf("%d",&st[i].rollno);
printf("\nEnter Name:");
scanf("%s",&st[i].name);
}
printf("\nStudent Information List:");
for(i=0;i<5;i++)
{
printf("\nRollno:%d, Name:%s",st[i].rollno,st[i].name);
}
getch(); return 0;
}
Output:
Enter Rollno:1
Enter Name:Rohan
Enter Rollno:2
Enter Name:mehul
Enter Rollno:3
Enter Name:mihir
Enter Rollno:4
Enter Name:pooja
Enter Rollno:5
Enter Name:mahesh

Student Information List:


Rollno:1, Name:Rohan
Rollno:2, Name:mehul
Rollno:3, Name:mihir
Rollno:4, Name:pooja
Rollno:5, Name:mahesh

2. Write a C structure StudentData with fields: studid,studname,total marks(up to 500).


Read the value of N number StudentData and Display them, if the value of total marks of any
student is more than 350 then display it’s all data.
#include<stdio.h>
#include<conio.h>

struct StudentData
{
int studid;
char studname[50];
int total_marks;
};

int main()
{
int n, i;

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 12


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
struct StudentData student[3];
clrscr();

for(i=0; i<3; i++)


{
printf("Enter details for student %d:\n", i+1);
printf("Student ID: ");
scanf("%d", &student[i].studid);
printf("Student Name: ");
scanf(" %[^\n]s", student[i].studname);
printf("Total Marks (out of 500): ");
scanf("%d", &student[i].total_marks);
}
printf("\nStudent details with total marks greater than 350:\n");
for(i=0; i<3; i++)
{
if(student[i].total_marks > 350)
{
printf("Student ID: %d\n", student[i].studid);
printf("Student Name: %s\n", student[i].studname);
printf("Total Marks: %d\n", student[i].total_marks);
}
}
getch();
return 0;
}

3. Write a C program that creates structure Employee with id, name and salary. Enter data
of five employees. Display data of those employees whose salary is more than 5000.
#include<stdio.h>
#include<string.h>
#include<conio.h>
struct employee
{
int eid;
char empname[10];
int salary;
};
int main()
{
int i,n,high;
struct employee emp[10];
clrscr();
printf("Enter Total number of Records:");
scanf("%d",&n);
printf("Enter Records of %d students",n);
for(i=0;i<n;i++)
{
printf("\nEnter Employee Name:");
scanf("%[^\n]s",&emp[i].empname);
printf("\nEnter Employee ID:");
scanf("%d",&emp[i].eid);
printf("\nEnter Employee Salary:");
scanf("%d",&emp[i].salary);

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 13


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
}
printf("Display Records of %d students",n);
for(i=0;i<n;i++)
{
printf("\nEnter Employee Name: %s",emp[i].empname);
printf("\nEnter Employee ID: %d",emp[i].eid);
printf("\nEnter Employee Salary: %d",emp[i].salary);
printf("\n-----------------------------------------\n");
}
high=emp[0].salary;
for(i=0;i<n;i++)
{
if(emp[i].salary >= high)
high=emp[i].salary;
}
printf("\n Highest Salary Employee Details :");
printf("\n EmpName \t EmpID \t EmpSalary");
printf("\n------------------------------------------\n");
for(i=0;i<n;i++)
{
if(emp[i].salary == high)
printf("\n %s\t\t%d \t %d \n",emp[i].empname,emp[i].eid,emp[i].salary);
}
printf("\n Salary More than 5000");
printf("\n EmpName \t EmpID \t EmpSalary");
printf("\n------------------------------------------\n");
for(i=0;i<n;i++)
{
if(emp[i].salary >= 5000)
printf("\n %s\t\t%d \t %d \n",emp[i].empname,emp[i].eid,emp[i].salary);
}
getch();
return 0;
}

4. Create a C structure, volume with fields: liter and millilitre. Read the value of two volumes
and add them, if the value of millilitre is more than 1000 then add it to liter value. (APRIL-
2022)
#include <stdio.h>
struct volume
{
int liter;
int milliliter;
};
int main()
{
struct volume v1, v2, result;
int total_ml;

printf("Enter the value of first volume in liter and milliliter separated by a space: ");
scanf("%d %d", &v1.liter, &v1.milliliter);

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 14


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills

printf("Enter the value of second volume in liter and milliliter separated by a space: ");
scanf("%d %d", &v2.liter, &v2.milliliter);

total_ml = v1.milliliter + v2.milliliter;

result.liter = v1.liter + v2.liter + (total_ml / 1000);


result.milliliter = total_ml % 1000;

printf("The total volume is %d liter and %d milliliter\n", result.liter, result.milliliter);

return 0;
}

5. Write C program to check the given string is palindrome or not using UDF.
#include<stdio.h>
#include<conio.h>
#include<string.h>

void chkpalin()
{
char s1[100],s2[100];
clrscr();

printf("Enter the string: ");


gets(s1);
strcpy(s2,s1);
strrev(s2);

if(!strcmp(s1,s2))
printf("string is palindrome");
else
printf("string is not palindrome");
}

int main()
{

chkpalin();
getch();
return 0;
}

Unit-2-3(Python Programming)
Do the following Practice programmes in Python Programming.
1. Write a Python program to display an average of 3 inputted numbers.
# Get the input from the user.
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
average = (num1 + num2 + num3) / 3
print("The average of the three numbers is:", average)

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 15


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
2. Write a Python program to calculate simple interest for a given principle amount, rate of
interest and no of years.
principle=float(input("Enter the principle amount:"))
time=int(input("Enter the time(years):"))
rate=float(input("Enter the rate:"))
simple_interest=(principle*time*rate)/100
print("The simple interest is:",simple_interest)

3. Write a Python program to display area of triangle.


base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
area = 0.5 * base * height
print("The area of the triangle is", area)

4. Write a Python program to calculate area of circle.


import math
def area_of_circle(radius):
return math.pi * radius ** 2

radius = float(input("Enter the radius of the circle: "))


area = area_of_circle(radius)
print("The area of the circle is:", area)

5. Write a Python program to calculate area of rectangle.


def area_simple_multiplication(length, width):
return length * width

length = 5
width = 8
result = area_simple_multiplication(length, width)
print(f"Area of Rectangle: {result}")

6. Write a Python program to check whether a number is divisible by 5 and 11 or not.


# This function checks if a number is divisible by 5 and 11
def check_divisibility(number):
if number % 5 == 0 and number % 11 == 0:
return True
else:
return False

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


if check_divisibility(number):
print("The number is divisible by both 5 and 11.")
else:
print("The number is not divisible by both 5 and 11.")

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 16


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
7. Write a python function which accept temperature in Celsius and convert into
Fahrenheit. F= (C * (9/5)) + 32
def celsius_to_fahrenheit(celsius):
fahrenheit = (celsius * 9/5) + 32
return fahrenheit

celsius = 20
fahrenheit = celsius_to_fahrenheit(celsius)

print(fahrenheit)

8. Write a python function which accept Fahrenheit and convert into Celsius.
C= (F-32) * 5 / 9
def fahrenheit_to_celsius(fahrenheit):
celsius = (5 * (fahrenheit - 32)) / 9.0
return celsius

fahrenheit = 100
celsius = fahrenheit_to_celsius(fahrenheit)
print(f"The temperature in Celsius is: {celsius:.2f}°C")

9. Write a Python program to check whether the entered alphabet is vowel or consonant.
letter = input("Enter an alphabet: ")
# Check if the alphabet is a vowel.
if letter in ('a', 'e', 'i', 'o', 'u'):
print(letter, "is a vowel.")
else:
print(letter, "is a consonant.")
10.Write a python UDF to calculate the sum of digits of the entered number.(No:1234
Ans=10)
num = input("Enter Number: ")
sum = 0

for i in num:
sum = sum + int(i)

print(sum)

11.Write a Python program to check whether the number is palindrome or not.


n=int(input("Enter number:"))
temp=n
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
print("The number is a palindrome!")
else:

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 17


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
print("The number isn't a palindrome!")

12.Write a Python program to count characters in the entered string.


def count_characters(string):
count = 0
for character in string:
count += 1
return count

string = "hello world"


print(count_characters(string))

13.Write a Python program to prints all letters except 'a' and 't'
# prints all letters except 'a' and 't'
i=0
str1 = 'SDJ International College'
while i < len(str1):
if str1[i] == 'a' or str1[i] == 't':
i += 1
continue
print('Current Letter :', str1[i])
i += 1

14.Write a Python program to find maximum between two numbers.


def max_of_two(a, b):
if a >= b:
return a
else:
return b

print(max_of_two(3, 5))
print(max_of_two(10, -2))
15.Write a Python program to check whether a character is alphabet or not.
print("Enter a Character: ")
c = input()
if c>='a' and c<='z':
print("\nIt is an alphabet")
elif c>='A' and c<='z':
print("\nIt is an alphabet")
else:
print("\nIt is not an alphabet!")
16.Write a Python program to check whether a character is uppercase or lowercase
alphabet.
string = 'GEEKSFORGEEKS' # Define a string containing only uppercase letters
print(string.isupper()) # Check if all characters in the string are uppercase and print the result

string = 'GeeksforGeeks'# Define a string with a mix of uppercase and lowercase letters

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 18


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
print(string.isupper()) # Check if all characters in the string are uppercase and print the result

Output:
True
False

17.Write a Python program to input marks of five subjects Physics, Chemistry, Biology,
Mathematics and Computer. Calculate percentage and grade according to following:
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
Percentage >= 40% : Grade E
Percentage < 40% : Grade F
rno=input("Enter Student Roll Number :")
sname=input("Enter Student Name :")
sub1=int(input("Enter marks of Physics: "))
sub2=int(input("Enter marks of Chemistry: "))
sub3=int(input("Enter marks of Biology: "))
sub4=int(input("Enter marks of Mathematics: "))
sub5=int(input("Enter marks of Computer: "))
tot=sub1 + sub2 + sub3 + sub4 + sub5
avg=tot / 5
print("Student Roll No is : ",rno)
print("Student Name is :",sname)
print("Marks of Physics:",sub1)
print("Marks of Chemistry:",sub2)
print("Marks of Biology:",sub3)
print("Marks of Mathematics:",sub4)
print("Marks of Computer:",sub5)
print("Total Marks : ",tot)
print("Percentage Marks : ",avg)
if(avg>=90):
print("Grade: A")
elif(avg>=80):
print("Grade: B")
elif(avg>=70):
print("Grade: C")
elif(avg>=60):
print("Grade: D")
elif(avg>=40):
print("Grade: E")
else:
print("Grade: F")

18.Write a Python program to input basic salary of an employee and calculate its Gross
salary according to following:
Basic Salary <= 10000 : HRA = 20%, DA = 80%
Basic Salary <= 20000 : HRA = 25%, DA = 90%
Basic Salary > 20000 : HRA = 30%, DA = 95%
basic_salary = float(input("Enter basic salary: "))

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 19


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
if basic_salary <= 10000:
hra = 20 / 100 * basic_salary
da = 80 / 100 * basic_salary
elif basic_salary <= 20000:
hra = 25 / 100 * basic_salary
da = 90 / 100 * basic_salary
else:
hra = 30 / 100 * basic_salary
da = 95 / 100 * basic_salary

gross_salary = basic_salary + hra + da


print("Gross salary:", gross_salary)

Python Loops:
1. Write a Python program to print the multiplication table of a given number using for
loop.

num = int(input("Enter a number: ")) # use a for loop to iterate from 1 to 10


for i in range(1, 11):
print(num, "x", i, "=", num * i)
2. Write a Python program to greet all the person names stored in a list List1.
List1 = [“Salman”, “Arayan”, “Sharukh”, “Virat”]
List1 = ["Salman", "Aryan", "Shahrukh", "Virat"]

for name in List1:


print("Hello", name)
3. Write a Python program to Fibonacci series of n numbers using while loop.
# Initialize the first two Fibonacci numbers.
a=0
b=1 Enter the number of terms: 10
Fibonacci Series:
# Get the number of terms from the user. 0
1
n = int(input("Enter the number of terms: "))
1
2
# Print the Fibonacci series. 3
print("Fibonacci Series:") 5
while n > 0: 8
print(a) 13
21
next_term = a + b
34
a=b
b = next_term
n -= 1

4. Write a Python program to calculate the factorial of a given number using for loop.
def factorial(n):
result = 1
for i in range(1, n + 1):
result *= i
return result

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 20


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
number = 5
print(factorial(number))

Python String & List:


1. Write a Python program to compare two strings.
str1 = input("Enter the first String: ")
str2 = input("Enter the second String: ")
if str1 == str2:
print ("First and second strings are equal and same")
else:
print ("First and second strings are not same")

2. Write a Python program to remove duplicates from a list.


duplicateLIST = [2, 4, 10, 20, 5, 2, 20, 4]
print(list(set(duplicateLIST)))

3. Write a Python program to append a list to the second list.


list1 = [1, 2, 3, 0]
list2 = ['Red', 'Green', 'Black'] OUTPUT:
[1, 2, 3, 0, 'Red', 'Green', 'Black']
final_list = list1 + list2

# Print the 'final_list,' which contains elements from both 'list1' and 'list2'
print(final_list)

4. Write a python code to print the sum of the given list in python.
total = 0
Input: [12, 15, 3, 10]
list1 = [11, 5, 17, 18, 23]
Output: 40
for i in range(0, len(list1)):
total = total + list1[i]
print("Sum of all elements in given list: ", total)

5. Write a python program that performs following(APRIL-2022)


a. Print length of string
b. Concatenate two strings
c. Reverse the string using slicing
print("Length of given string is" , len("Hello, World!"))
str1="Hello"
str2="World"
str=str1+str2
print("Concatenated two different strings:",str)
print(str[::-1]) # Reversing the given string

6. Create a python list and perform the following operation: (APRIL-2022)


a. Sort the List
b. Display sum of the all elements of the list
c. Display last element of the list
vowels = ['e', 'a', 'u', 'o', 'i']# vowels list
vowels.sort()# sort the vowels
print('Sorted list:', vowels)# print vowels

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 21


A.Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
####Display sum of the all elements of the list#######
total = 0
list1 = [11, 5, 17, 18, 23]
for i in range(0, len(list1)):
total = total + list1[i]
print("Sum of all elements in given list: ", total)

####Display sum of the all elements of the list#######


list1 = [1, 2, 3, 4, 5]
last_element = list1[-1]
print(last_element)
7. Write a python program that store characters of a word as List elements and removes
vowels from the list. (APRIL-2022)
Example:
Old List : [‘p’,’r’,’o’,’g’,’r’,’a’,’m’]
New List: [‘p’,’r’,’g’,’r’,’m’]
string = "SDJ INTERNATONAL COLLEGE"

vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
result = ""

for i in range(len(string)):
if string[i] not in vowels:
result = result + string[i]

print("\nAfter removing Vowels: ", result)

Extra Practice:
#Use the for loop to iterate a dictionary in the Python script.
capitals = {"USA":"Washington D.C.", "France":"Paris", "India":"New Delhi"}

for key in capitals:


print("Key = " + key + ", Value = " + capitals[key])

#Convert List to Set

names=['Deepak','Reema','John','Deepak','Munna','Reema','Deepak','Amit','John','Reema']
nameset=set(names)
print(nameset)

PROF. BHUMIKA PATEL Smart work + Patience + Believe = Success Page 22

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy