Python Problem Sheet 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

1.

Predict the output of the following programs without executing it in a python


interpreter
a) print(“Hello\n”,”\tWelcome”,sep=”8888”,end=”9999”)
print(“Welcome to the world of programming”,end=”\n\n\t”)
print(“Good”,”Morning”,sep=”\n”)

print(len(“\n\n\t\n\n\tHelloIndia”))

b) print(“Hello”,”\t\t\t”,end=”Welcome”)
print(“Good”,”Morning”,sep=”gggg”)

2. Write a python program to print the following in the same format as specified
Welcome to the
department of CSE
Happy day

3. Write a python function which accepts the inputs name and department and prints the
following message –
(If the inputs are Sethuram and CSE), the output must be
I welcome Sethuram to CSE department

(If the inputs are xxx and Mechanical) , the output must be
I welcome xxx to Mechanical department

4. Write a python function which accepts 3 inputs name, city and state and displays the
message like the following

(The inputs are Helen, Madurai, Tamilnadu)


Helen
Madurai
Tamil Nadu
5. Write the python functions to perform add, subtract, multiply and divide
Each of these functions accepts 2 numbers and gives the appropriate result.

6. Write a python function which accepts 2 numbers (a and b) and returns


ab (a to the power of b) (Hint: Use a**b)

7. Write a python function which accepts 2 numbers (a and b) and returns the remainder
of dividing the first number by the second number.

8. Write a python function which accepts 2 numbers (a and b) and returns the quotient of
dividing the first number by the second number.

9. Write a python function which accepts the diameter of a circular pizza and price per
square inch as inputs and returns the cost of the pizza as output

10.

11.

12.

13. Write a python function which accepts a number as input and prints whether it is even
or odd

14. Write a python function which accepts name and age as input and prints appropriate
string as output
If age<=30 the person is young
If age>30 and age<=60, the person is middle aged
If age>60, the person is old

For example: if name=”yyy” and age=56, then output should be


yyy is middle aged

15. Write a python function which accepts three numbers and returns the largest of the
three numbers.

16. Write a python function which accepts the inputs A,B and C and prints the roots of the
quadratic equation
Ax2+Bx+C=0

17. Simulate a password enabled door-locking system where the door accepts a unique
password
and displays the message “YOU CAN ENTER INSIDE”. If any other password is given, the
message should be “YOU ARE NOT ALLOWED INSIDE”.

18.

19.

20. Write a python functions to check whether a number is


a) Positive or negative
b) Divisible by 17 or not

21.
22.

23. a) Write a python function which accepts a message and count as inputs and displays
the message, count number of times
For example Suppose the count is 5 and the message is “Hello”, the output should be
Hello
Hello
Hello
Hello
Hello

24. Write a python function which accepts 2 numbers and returns the product of 2 numbers
without using * operator

25. Write a python function which accepts 2 numbers (a and b) and returns ab without using
the ** operator.

26. Write a python function which accepts an n-digit integer and returns the sum of the
digits of the number

27. Write a python function which accepts an n-digit integer and returns the reverse of the
number

28. Write a python program which displays the following pattern given the size n,
If n=4, the program has to display 4 rows
1
1 2
1 2 3
1 2 3 4

29. Write a python program which displays the following pattern given the size n,
If n=5, the program has to display 5 rows
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
30.

31. Write a python function which accepts 2 integers (a and b), returns the average of all
the integers between a and b excluding them (Here a<b)

For example : If a = 2 and b = 10


You need to calculate the average as (3+4+5+6+7+8+9)/7

For example if a = -10 and b = 0


You need to calculate the average as (-9-8-7-6-5-4-3-2-1)/9

32. Write a python function which accepts a positive integer and prints whether a number is
prime or composite.

33. Write a python function which accepts 2 positive numbers (a and b), returns the sum of
all odd numbers between a and b (excluding a and b)

34. A) Write a python function which accepts 2 positive numbers (a and b) and displays all
numbers between a and b (including a and b) divisible by n (which is another input)

For example: if a = 100 , b = 790, n=50


The output should be
100 150 200 250 300 350 400 450 500 550 600 650 700 750

B) Also display the count of how many such numbers are there.
In the above example the count is 14

35. Write a python function which generates all prime numbers between any 2 given
numbers (a and b) including a and b

36.
37.

38.

39.

40.

41.
42.

43. Find the taylor’s series expansion for a given value of n


If n=5, find the sum of 5 times of the series

sin(x) = x-(x3/3!)+(x5/5!)-(x7/7!)+…..
Where x is in radians

The questions for the test would be similar to the Questions in the above problem sheet

FIRST CODING TEST ON 23rd August 2017 (Wednesday) , Time: 1.5 Hours, Time: 4.30 to 6.00 PM,
Venue: Oracle Lab (E4 Block, Ground Floor)

The book to be referred is John Zelle

The pattern of questions would be the following

4 Questions will be asked

2 Easy Level (2*4 = 8 Marks)

1 Medium Level (1*7 = 7 Marks)

1 Hard Level (1*10 = 10 Marks)

TOTAL 25 Marks

Complete Execution of the program will fetch you full marks for that question

You might also like