Assignment-1
Programming using python
Please pay attention to indentation and spacing.
Submit By: 14 Dec 2024 [Link will be provided]
Attempt All Questions
Q1. Define problem. Explain three main methodologies for problem solving.
Q2. Define algorithm. Write an algorithm for adding four numbers. Also draw its flow chart.
Q3. Difference between algorithm and a program.
Q4. What are keywords and what are identifiers. Identify valid or invalid identifiers from the
following also give reason:
a) English marks = 98
b) Total$ = 56
c) 1stnumber = 90
d) _Maths = 100
e) Max_of_3_marks = 100
f) for = 60
Q5. What will be the output or reason of error for the following:
a) print('test ' * 3.0)
b) print(3 + '5 '+ 7)
c) float(4+int(2.39)%2)
d) print(list('Hello'))
e) for i in range(1,5):
j = 0
while j<i:
print(j, end=” “)
j+=1
f) Word1= " Hello first year students"
Word2=" Hello second year students"
for i in Word1:
if i in Word2:
print(i , end=" ")
g) x=3
y=2
if x>2:
if y>2:
z = x+y
print("Z is: " , z)
else:
print("x is: ", x)
Q6. Write a program that accepts x and n as input to compute the following series and print ther
series(Use functions).
x – (x)2 /2!+ (x)3 /3! – (x)4 /4!+ …….n terms
Q7. Consider the following code
for k in ‘Computer Science’:
if k = ‘e’:
S1
print(k,end = “,”)
compare the output when S1 is replaced with each of the following statements:
i) Break
ii) Continue
iii) Pass
Q8. Write a function SumDigits(Num) which computes the sum of digits of a number Num and
returns it.
Q9. Write a program with following functions:
i) countVowel(Str1) to count the vowels in a string.
ii) replaceChar(Str1) to replace all the occurance of the character ‘a’ with a space.
iii) reverseString(Str1) to reverse a string.
Also call these functions and provide the output for the given string Str1.
Str1 = ‘Happiness depends upon ourselves’
Q10. Write a function factors(n1) that returns a set of all the factors of the number n1.