CT2 Set 3
CT2 Set 3
SET 3
College of Engineering and Technology OFF LINE
CYCLE TEST – II
Academic Year: 2022-2023 (EVEN Semester)
(a) | (c) /
(b) // (d) %
7. What will be the output of given Python code? 5 2 4 1
7
n=7
c=0
while(n):
if(n>5):
c=c+n-1
n=n-1
else:
break
print(n)
print(c)
(a) 5 11 (c) 7 11
(b) 59 (d) 5 2
What is the order of precedence in python? 5 2 4 1
8 a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction
c) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition
d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
Part B (3x4Marks=12 Marks)
Answer all questions
Sl.N Question C PO BL Mar
o O ks
9 In C, explain strtok function with an example. 3 2 4 4
The strtok in c is a library function which breaks the given string into a series of tokens using the
delimiter passed as a parameter. Like if there is a string with multiple words separated by comma
then we can use this function strtok in c with comma(,) as a delimiter to split this string based on
comma.
char *strtok(char *string, const char *delimiter)
10 Write a Python program to find the average of 10 numbers using while loop 4 2 4 4
a=[19, 25, 74, 38, 99, 39, 18, 83, 10, 50]
count=0
sum=0
while (count<len(a)):
sum=sum+a[count]
count=count+1
print('average of list',a,'is',(sum/len(a)))
11 How will you create an empty Data Frame in pandas? 5 2 2 4
To create an empty dataframe by importing pandas from the python library. Later, using the
pd.DataFrame(), create an empty dataframe without rows and columns as shown in the below
example. Note that the DataFrame() class available in the pandas library is similar to the
constructor which is used to construct the class.
df = pd.DataFrame()
Part C( 3x10=30 Marks)
Answer all questions
Sl.N Question C PO BL Mar
o O ks
12 Write a C program to sort a string array in ascending order 10 marks 3 2 4 10
a.
#include <stdio.h>
void main()
{
char str[100],ch;
int i,j,l;
printf("\n\nSort a string array in ascending order :\n");
printf(" \n");
printf("Input the string : ");
fgets(str, sizeof str, stdin);
l=strlen(str);
/* sorting process */
for(i=1;i<l;i++)
for(j=0;j<l-i;j++)
if(str[j]>str[j+1])
{
ch=str[j];
str[j] = str[j+1];
str[j+1]=ch;
}
printf("After sorting the string appears like : \n");
printf("%s\n\n",str);
}
OR
12 Explain the string functions with its syntax :Strlen( ), Strcat ( ), Strcmp( ), Strrev( ), Strcpy( ) 3 1 2 10
b. Strlen( ) (Explanation and any one syntax 2 marks)
The strlen() function takes a string as an argument and returns its length. The returned value is of
type size_t (an unsigned integer type).
Syntax :
n=strlen(str);
length = strlen(str);
length = strlen("pritesh");
char *str = "pritesh";
Strcat ( ) (Explanation and any one syntax 2 marks)
Function takes 2 Strings / Character Array as Parameter
Appends second string at the end of First String. Parameter Taken - 2 Character Arrays /
Strings Return Type - Character Array / String
Syntax :
char* strcat ( char * s1, char * s2);
Strcmp( ) (Explanation and any one syntax 2 marks)
Function takes two Strings as parameter.
It returns integer .
Syntax :
int strcmp ( char *s1, char *s2 ) ;
Strrev( ) (Explanation and any one syntax 2 marks)
reverses a given string in C language. Syntax for strrev( ) function is
given below.
char *strrev(char *string);
strrev() function is nonstandard function which may not available in
standard library in C.
Strcpy( ) (Explanation and any one syntax 2 marks)
Function takes two Strings as parameter.
Header File : String.h
It returns string.
Purpose : Copies String2 into String1.
Original contents of String1 will be lost.
Original contents of String2 will remains as it is.
Syntax :
char * strcpy ( char *string1, char *string2 ) ;
13 Write a Python to get the age of a person as input and report whether the 4 1 2 10
a. person is eligible to vote or not 10 marks
age = int(input("Enter age : "))
Tuples are defined by enclosing elements in parentheses (), separated by a comma. The
following declares a tuple type variable.
tpl=() # empty tuple
print(tpl) #output: ()
OR
14 Describe the following basic operation which can be performed on Pandas 5 1 2 10
b. DataFrame with example
i) Creating a DataFrame 5 marks
A Pandas DataFrame is a 2 dimensional data structure, like a 2
dimensional array, or a table with rows and columns.
Example
Create a simple Pandas DataFrame:
import pandas as pd
data = {
"calories": [420, 380, 390],
"duration": [50, 40, 45]
}
#load data into a DataFrame object:
df = pd.DataFrame(data)
print(df)
ii) Iterating over rows and columns 5 marks
Iteration is a general term for taking each item of something, one
after another. Pandas DataFrame consists of rows and columns so, in
order to iterate over dataframe, we have to iterate a dataframe like a
dictionary. In a dictionary, we iterate over the keys of the object in
the same way we have to iterate in dataframe.
In this article, we are using “nba.csv” file to download the CSV,
In Pandas Dataframe we can iterate an element in two ways: