unit 1 and 2 Flashcards

1
Q

3 steps to solve a problem

A

1- Understanding the prob (input)
2- Analysing the prob (process)
3- Developing the soln (output)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Top down approach

A

a system design approach where the design starts from the complete system which is then divided into smaller sub applications with more details.

the problem is broken into smaller ones and then the process is repeated with each problem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Bottom up approach used in ______

A

research

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

techniques and design used to solve a problem

A
  1. Pseudocode
  2. Algorithm
  3. Flowchart
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Pseudocode

A

it is an informal high level description of the operating principle of a computer program

it is used to document the program or module design (algorithm)

pseudo means false. pseudocode means false code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Algorithm

A

can be defined as a complete, unambiguous, finite number of logical steps for solving a specific problem
eg: finding whether a number is prime or not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

flowchart definition

A

diagrammatic representation
-of an algorithm work flow or process
-illustrates a solution model to a given problem

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Problem

A

a well defined tasks or challenge that requires a computational soln.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

in depth steps for problem solving

A
  1. Understanding/Analysing the problem
  2. Developing the algorithm/pseudocode
  3. Coding
  4. Testing and debugging
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Top down design is based on ___ approach

A

decomposition approach

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

top down approach is followed by ________

A

structural programming languages like C, FORTRAN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Advtgs of top down approach

A
  • better understanding of entire program and less info about subprogram
  • well established communication is not required
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Disadvgs of top down approach

A

the codes can be repeated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

symbols of a flowchart

A
  1. Terminal - start/end points - OVAL
  2. Flowlines - default flow is left to right and top to bottom- ARROWS
  3. Input/Output - input/output - PARALLELOGRAM
  4. Process - mathematical compution / variable assignment - RECTANGLE
  5. Decision - true/false statement being tested - DIAMOND/KITE
  6. Module Call - program control is HORIZONTAL LINES IN RECT and specific task module is VERTICAL LINES IN RECT
  7. Connector - allows to connect two flowcharts on same or dif page - SMALL CIRCLE WITH A LETTER IN IT (on page)
    SMALL PENTAGON WITH LETTER IN IT (off page)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

write a flowchart for print sum of two numbers

A

start -> read input a -> read input b ->calc sum of a & b -> print the sum -> end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

write a algorithm for print sum of two numbers

A
  1. define the function is - vowel with character as a paramether passed.
  2. check whether the charater is vowel or not & store it in is-char-vowel
  3. return the value of is-char-vowel
  4. call the function “in-vowel” & test the function with different characters.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Semantic error

A

when there is some logical errors
OR
there is no end to the loop in the syntax

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Functions definition and use

A

allows us to create a block of code that can be reused to perform a specific task

they make the code reusable and more organised

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

function can be defined using ______ keyword

A

def

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

structure of function

A

name, parameters and body

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

functions can be called ________ times to reuse its functionality

A

multiple

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

parameter

A

named entity in a function definition that specifies an argument that function can accept

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Eg: def product_of_two_numbers (a, b)
Here, a and b are

A

parameters example

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Argument

A

the actual value that is passed to a function when it is called. It is used to assign a value to the corresponding parameter in the function defined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

function declaration

A

the act of defining a functions name, parameters and body. It doesnt run the function but sets it up, to be called later.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

function call (invoking the function)

A

the act of running a function by using its name followed by arguments in parentheses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

return value

A

the value a function sends back to the place where the function was called from. it is specified by the return keyword in a function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Flowchart shows the steps as ______

A

boxes of various kinds and their order by connecting the boxes with arrows

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Flowchart is used in

A

analysing, designing, documenting or managing a process or program in various fields

30
Q

Variable names must start with?

A

letters or underscores

31
Q

Which error comes up if a variable name starts with a number?

A

Syntax error : invalid decimal literal

32
Q

in python variables are ____?

A

case-sensitive

33
Q

Example of ‘cannot assign value to a literal’?

34
Q

code for checking type of variable?

A

type(variable)

35
Q

% , /, //

A

% - modulo - gives remainder
/ - simple division - returns float
// - returns quotient integer

36
Q

converting a string into all uppercase and printing it

A

print(string_variable.upper())

37
Q

converting a string into all lowercase and printing it

A

print(string_variable.lower())

38
Q

capitalising the first letter of a string, making the rest of the letters lowercase and printing it

A

print(string_variable.capitalize())

z important

39
Q

Checking if a string has all lowercase letters (True/False)

A

print(str_variable.islower())

40
Q

Checking if a string has all uppercase letters (True/False)

A

print(str_variable.isupper())

41
Q

Checking the starting characters in a string (True/False)

A

st = “Hello World”
print(st.startswith(‘Hell’))

42
Q

Checking if a string has first letter capital and rest all lowercase (titlecase) (True/False)

A

print(str_variable.istitle())

43
Q

Checking if the string is a digit (True/False)

A

only works on strings and checks all characters
print(“123”.isdigit())

44
Q

Checking the ending characters in a string (True/False)

A

st = “Hello World”
print(st.endswith(‘World’))

45
Q

Checking if string is alpha (True/False)

A

print(‘23’.isalpha())
print(‘2A’.isalpha())
print(‘ABC’.isalpha())

46
Q

Checking if string is numeric alpha (True/False)

A

print(‘ABC123’.isalnum())
print(‘ABC 123’.isalnum())

47
Q

Finding a substring within a string
#Returns index value

A

print(‘Hello World’.find(‘Hello’)) #Output 0
print(‘Hello World’.find(‘ello’)) #Output 1
print(‘Hello World’.find(‘llo’)) #Output 2
print(‘Hello World’.find(‘lo’)) #Output 3
print(‘Hello World’.find(‘Ello’)) #Output -1
print(‘Hello World’.find(‘plo’)) #Output -1

48
Q

extract substring from one index value to another

A

str=’Hello World’
print(‘Hello World’[0:5])

49
Q

How to use the in keyword to check whether a character or a sequence of characters exists within a specific string?

A

print(‘Hello’ in ‘Hello World’) #true
print(‘ello’ in ‘Hello World’) #true
print(‘Ello’ in ‘Hello World’) #False
print(‘bello’ in ‘Hello World’) #False

50
Q

which operator is used to check if the 2 strings are the same?

A

==
output is true or false

51
Q

In Python there is no distinct data type for single characters. Both strings and single characters

A

message = “69Hello Message”
print(message[0]) #note there is square bracket
print(type(message[0])) #<class ‘str’>

52
Q

3 ways for string concatenation in python

A

s1 = “Hello”
s2 = “World”
res = s1 + “ “ + s2

s1 = “Python”
s2 = “programming”
#use an f string to create a formatted string that includes both variables
result = f”{s1} is a popular {s2}.”

a = 5
b = 10
print(“The sum of {} and {} is {}.”.format(a, b, a + b))

53
Q

Program to print no. of hours in a day

A

print (24)

54
Q

Calling function without passing an argument Python will throw a _______ Error

A

Type Error

55
Q

def product_of_two_numbers(a,b):
print(a * b)

product=product_of_two_numbers(2,6)
print(product) #prints None - WHY?

A

12 is printed inside the function

#product stores None because the function doesn’t return anything
#In Python, if no return is used, the function returns None by default

56
Q

create a Python function named is_vowel that determines whether a given character is a vowel or not.

The input consists of a single parameter: char. Char is the character that needs to be tested.

The output should be a boolean value, returning True if the character is a vowel and False if it’s not.

A

def is_vowel(char):
vowels=’aeiou’
is_char_vowel = char in vowels
return is_char_vowel

is_vowel(‘a’)

57
Q

create a Python function named average_of_five_numbers that calculates the average of five given integers and returns the result.

The input consists of five integers: a, b, c, d, e.

The output should be a single integer, which is the average of a, b, c, d, e.

A

def average_of_five_numbers(a,b,c,d,e):
average =(a+b+c+d+e) /5
return average

print(average_of_five_numbers(15,14,12,13,17)) #output

58
Q

Logical OR | operator

A

print(True|True) #Output: True

print(True|False) #Output: True

print(False|True) #Output: True

print(False|False) #Output: False

59
Q

What happens when
if(False):
print(False)

A

no result because condition is false

60
Q

Logical AND & operator

A

print(True&True) #Output: True

print(True&False) #Output: False

print(False&True) #Output: False

print(False&False) #Output: False

61
Q

Logical XOR ^ operator

A

print(True^True) #Output: False

print(True^False) #Output: True

print(False^True) #Output: True

print(False^False) #Output: False

62
Q

Logical ~ (NOT) Operator

A

print(~True) #Output: False

print(~False) #Output: True

63
Q

print(10 / 0) # Division by zero gives _____ error

A

ZeroDivisionError

64
Q

taking input and storing it in a variable example

A

age = int(input(“Enter age: “))

64
Q

text = “Hello”
print(text[10]) # Index out of range gives _____ error

A

IndexError: string index out of range

65
Q

age = int(input(“Enter age: “)) #if input is string “ten” then we get a _______ error

A

Value Error

66
Q

when calling a function, if the argument is missing, we get a ____Error

67
Q

why use lists?

A

Lists = Flexible, dynamic containers for organizing and working with collections of data.

68
Q

marks = [25, 56, 67]
what are the basic operations you can apply to this to get results in integers?

A

print(max(marks))
print(min(marks))
print(len(marks))
print(sum(marks))

69
Q

what are the methods one can apply to lists?
animals = [‘Cat’, ‘Dog’, ‘Elephant’]

A

animals.extend([‘Giraffe’, ‘Horse’])
#adds these items at the end

animals += [‘Lion’, ‘Monkey’]
#again adds these items at the end of the list

print(animals.index(“Cat”)) #index is starting from zero

animals.append([‘Tiger’, ‘Cheetah’])
#adds the list at the end as a new item

animals.insert(2, ‘Hippo’)
#use of index

marks.remove(‘Cat’)

print(‘Hippo’ in animals) #check if a value exists in the list

print(animals.index(‘Horse’)) #returns index - throws a value error if item not in list