UNIT_1 () - Mind Map

UNIT_1 ()

DAY_2

DEBUGING

Write a program that accepts a sentence as
input and prints the same.
Input format
The input consists of a sentence.
Output format
The output prints the sentence.

string = input()
print(string)

Input 1
make life ridiculously amazing

Output 1
make life ridiculously amazing

Raveena wants to welcome everyone who
attends the Inauguration Ceremony. Given
thename of the person, she needs to print
the following message. "Hi (name) ,
welcome to the inauguration ceremony"
Input format: The
input consists of a string.
Output format:
The output prints the custom message.

name = input()
print ("Hi " +(name)+" , welcome to the
inauguration ceremony")

Input 1
alice
Input 2
Raksha

Output 1
Hi alice , welcome to the inauguration
ceremony
Output 2
Hi Raksha , welcome to the inauguration
ceremony

Write a program to print the ASCII value of
a given character.
Input format
The input consists of a character.
Output format
The output prints the ASCII value.

c = input()
print(ord(c))

Input 1
k
Input 2
U

Output 1
107
Output 2
85

Write a program to obtain and display the
newly joined student name and age detail.
Input format
The first input is a string that corresponds
to the name of the student
The second input is an integer that
corresponds to the age of the student
Output format
The output should display the details as
given in the sample output.
<name> age is <age>

Header Snippet
name = input()
age = int(input())
print(name,"age is",age)

Input 1
ram
30

Output 1
ram age is 30

Write a program to find the area of a
rectangle.
Input format
Input consists of length and breadth
separated by space
Output format
Output prints the area of the rectangle

Header Snippet
length = int(input())
breadth = int(input())
print (length*breadth)

Input 1
10
2

Output 1
20

PROGRAM

Fill in the blanks so that the code prints
Output: Arise awake and stop not till the
goal is reached
Input format
No console input.
Output format The
output prints the sentence.

word1 = " Arise"
word2 = " stop not "
word3 = " goal is "
print(word1 + " awake and" + word2 + "till
the" + word3 + "reached")

input_1

Output 1
Arise awake and stop not till the goal is
reached

This code is supposed to take two
numbers, divide one by another so that the
result isequal to 1, and display the result
on the screen. Unfortunately, there is an
error in the code.Find the error and fix it,
so that the output is correct.
Input format
No console input.
Output format
The output prints 1.

numerator = 10
denominator = 10
result = (numerator / denominator)
print(result)

Input 1

Write a Python script that outputs
"Learning Python is fun!" to the screen.
Input format
No console input.
Output format
Output: Learning Python is fun!

print ("Learning Python is fun")

Input 1

Output 1
Learning Python is fun

Perform the task given in program
comments.
Input format
No console input
Output format
The output prints the sentence.

print(“If you want to shine like a sun first burn like a sun")
print("If you want to shine like a sun"+" first burn like a sun")

Input 1

Output 1
If you want to shine like a sun first burn like
a sun first burn like a sun

Perform the task given in program
comments.
Input format
No console input.
Output format
The output prints the speed rounded off to
two decimal places.

d=245
t=8
s=d/t
print('{:.2f}'.format(s))

Input 1

Output 1
30.62

MCQ

Which character is used in Python to make
a single-line comment?

#

Which of the following is not a keyword in
Python language?

val

In Python 3, the maximum value for an
integer is 2^63 - 1

False

What is the type of inf?

Float

What does ~~~~~~5 evaluate to?

+5

Which of the following is incorrect?

float(’12+34′)

What is the result of round(0.5) –
round(-0.5)?

2.0

Fill the following blank to get the following
output.
Output:
20.00

print("%.2f" %a)

What are all the type castings possible in
Python?
1. integer to string
2. float to string
3. string to float
4. float to complex

1,2,4

In which datatype does the console takes
input, by default.

string

DAY_1

MCQ

Which of the following are valid Python
variable names

soln11

What is the maximum length of an
identifier in Python?

Identifier can be of any length

Which of the following statement is false?

Variable name can begin with
number.

Why are local variable names beginning
with an underscore not allowed in Python?

they are used to indicate a
private variables of a class

What is the output of the following number
conversion?
z = complex(1.25)

(1.25+0j)

If we change one data type to another,
then it is called?

Type conversion
Typecasting

What is type casting in python?

Change data type property

Which of the following can convert the
string to float number?

float(str)

Which of the following is the example of
the type casting?

int(2)
str(2),str(list)

x=3.123, then int(x) will give

3

PROGRAM

Write a program to read a number and
print it.
Input format:
The input consists of an integer.
Output format:
The output prints the integer.

a=int(input())
print (a)

Input_1(484)

output_1(484)

Write a program to read a string and print
it.
Input format:
The input consists of a string.
Output format: The output prints the
string.
Sample testcases

b=str(input())
print(b)

Input_1
(Life is bliss)

Output_1
(Life is bliss)

Write a program to read a decimal value
and print it.
Input format:
The input consists of a float value. Output
format:
The output prints the float value.

c=float(input())
print (c)

Input 1
48.2648
Input 2
36.25
Input 3
88.888848

Output 1
48.2648
Output 2
36.25
Output 3
88.888848

Write a program to read a float value and
round it off to two decimal places.
Input format:
The input consists of a floating-point
number.
Output format:
The output prints the number.
Note: Display two digits after the decimal
point.

d=format(float(input()),".2f")
print (d)

Input 1
84.4864
Input 2
26.8624

Output 1
84.49
Output 2
26.86

This code is supposed to display "2 + 2 =
4" on the screen, but there is an error. Find
the
error in the code and fix it, so that the
output is correct.
Input format
No console input.
Output format
The output prints the answer.

print("2 + 2 = " + str(2+2))

Input 1

Output 1
2 + 2 = 4

DAY_6

PROGRAM

Write a Python program to construct the
following pattern, using a nested for loop.
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Input format
No input console.
Output format
The output should print the desired
pattern as shown in the above sample
image.

for i in range(0,5):
for j in range(0,i+1):
print("* ",end="")
print()
for i in range(5,0,-1):
for j in range (0,i-1):
print("* ",end="")
print()

Input 1

Output 1
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

Write a Python program to calculate the
sum and average of n integer numbers
(input from the user). Input 0 to finish.
Input format
The input should be the n integers.
Output format
The output prints the sum and average of
n integer numbers.
Refer sample output for better
understanding Code constraints
Give input as 0, to exit.

sum=0.0
b=0
n=1
while (n!=0):
n=int(input())
sum=sum+n
b=b+1
print("Average of the numbers
is:",sum/(b-1))
print("Sum of the numbers is:",sum)

Input 1
12
15
18
22
34
0

Output 1
Average of the numbers is: 20.2
Sum of the numbers is: 101.0

Write a program to find the factorial of a
number.
Input format
The input should be an integer.
Output format
The output prints the factorial of the input
number.

a=int(input())
fact=1
while(a!=0):
fact=fact*a
a=a-1
print(fact)

Input 1
5

Output 1
120

Write a Python program to create the
multiplication table (from 1 to 10) of a
number.
Input format
The input should be an integer.
Output format
The output prints the multiplication table
up to 10 of the input number.

n=int(input())
a=1
while(a<=10):
print(n,"x",a,"=",a*n)
a=a+1

Input 1
5

Output 1
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

Write a program to display the product of
the digits of a number accepted from the
user.
Input format
The input should be an integer.
Output format
The output prints the product of digits of
the number

n=int(input())
p=1
while (n!=0):
p=p*(n%10)
n=n//10
print(p)

Input 1
2345

Output 1
120

MCQ

What is the output of the following?

x = 'abcd'
for i in x:
print(i.upper())

A
B
C
D

What is the output of the following
program?

i=1
while(i<3):
j=0
while(j<3):
print(i%3)
j=j+1
i=i+1

1 1 1 2 2 2

What will be the output of the following
code?
i=1
while(i<=3):
for j in range(4,0,-2):
print(i*j)
i=i+1

4 2 8 4 12 6

What is the purpose of the while() method?

It will run a loop as long as
the condition is true.

Which keyword is used to immediately
terminate a loop

break

Which keyword is used to end the current
iteration of a loop skipping the remaining
statements in the loop body and returning
to the top of the loop.

continue

What is the output of the following?

st= "my name is x"
for i in range(len(st)):
print(st)
break

my name is x

When does the code block following
while(x<100) execute?

When x is less than one
hundred

How many times inner for loop will be
executed in the below code?

i=0
while(True):
for j in range(4,0,-2):
print(i*j)
print('')
i=i+1
if(i%2==0):
break

2

Why would you use WHILE loop

To repeat code until a
condition is met

DAY_8

PROGRAM

Write a python program to print the
Fibonacci series.
Input format
The input consists of the value of n.
Output format
The output prints the Fibonacci sequence.

n=int(input())
i=1
n1=0
n2=1
while(i<=n):
print(n1)
n3=n1+n2
n1=n2
n2=n3
i=i+1

Input 1
5

Output 1
0
1
1
2
3

John's little brother is struggling with
Maths. He decided to design a calculator
with basic operations such as Addition,
Subtraction, Multiplication and Division.
The calculator should input two float
numbers and an operator from the user. It
should perform an operation according to
the operator entered and must take input
in given format.
Input format
First line contains 2 float numbers
separated by spaces.
Second line contains operator which is
going to perform on those inputs.
Output format
Print the output

num=input().split(" ")
op=input()
if(op=="+"):
print(float(num[0])+float(num[1]))
elif(op=="-"):
print(float(num[0])-float(num[1]))
elif(op=="*"):
print(float(num[0])*float(num[1]))
elif(op=="/"):
print(float(num[0])/float(num[1]))

Input 1
20 8
+

Input 2
20 8
-

Input 3
20 8
*

Input 4
20 8
/

Output 1
28.0

Output 2
12.0

Output 3
160.0

Output 4
2.5

Write a program to accept two integer
values from the user and return their
product. If the product is greater than
1000, then return their sum
Input format
Integer 1 in first line
Integer 2 in second line
Output format
Sum or product of given two numbers

a=int(input())
b=int(input())
c=0
c=a*b
if(c>1000):
print(a+b)
else:
print(c)

Input 1
5
123

Input 2
5
654

Output 1
615

Output 2
659

Write a python program to obtain m and n
and print "True" if m is greater than n, else
print"False".
Input format
The first line of the input consists of an
integer.
The second line of the input consists of an
integer.
Output format
The output displays the result.

m=int(input())
n=int(input())
if(m>n):
print("False")
else:
print("True")

Input 1
15
78

Input 2
45
13

Output 1
True

Output 2
False

Write a program to print the sum of 1 to
n.While calculating sum omit the number
which
are multiple of x
Note: Use continue concept.
Input format
First line of the input consist of an integer
n.
Second line of the input consist of an
integer x.
Output format
Output prints the sum of elements.

t=0
n=int(input())
x=int(input())
for i in range(0,n+1):
if(i%x==0):
continue
t=t+i
print(t)

Input 1
50
6

Input 2
20
2

Output 1
1009

Output 2
100

MCQ

What is the output of the following?
i = 2
while True:
if i%3 == 0:
break
print(i)
i += 2

2 4

What is the output of the following?

for i in range(2.0):
print(i)

error

What is the output of the following?
i=0
while(1):
i++
print i
if(i==4):
break

syntax error

How many times is a do while loop
guaranteed to loop?

1

What is the output of the following?
True = False
while True:
print(True)
break

syntax error

What is the output of the following?
x = 'abcd'
for i in range(len(x)):
print(i)

0 1 2 3

What is the output of the following?
m=2
total=0;
while(m<6):
total=total+m
m=m+1
print(total)

14

What is the output of the following?
while True:
print True
break

True

What is the output of the following?
x = 'abcd'
for i in range(x):
print(i)

error

What is the output of the following?
for i in range(10):
if i == 5:
break
else:
print(I)
else:
print("Here")

0 1 2 3 4

DAY_9

DEBUGING

Write a program to obtain a number and
print it as a sum of two prime numbers.
Input format
The input consists of a number.
Output format
The output prints the number as a sum of
two prime numbers.

num = int(input())
ctr = 0
for i in range (2,int((num/2)+1)):
temp1 = i
temp2 = num-i
for j in range(2,int((i/2)+1)):
if(i%j==0):
ctr += 1
break
if(ctr==0):
for j in range (2,int((num-i)/2)+1):
if((num-i)%j==0):
ctr += 1
break
if(ctr==0):
print(i,"+",num-i)
ctr = 0

Input 1
16

Input 2
30

Output 1
3 + 13
5 + 11

Output 2
7 + 23
11 + 19
13 + 17

Write a program to find out the sum of an
AP series.
Input format
The input consists of the first number of
the AP series, the number of terms in the
AP
series, and the common difference of the
AP series.
Output format
The output prints the sum.

Header Snippet

sum1 = 0
n1 = float(input())
nterm = float(input())
cd = float(input())
for i in range(1,int(nterm),1):
sum1=sum1+i*cd
sum1+=n1*nterm
print(sum1)

Input 1
1
10
4

Output 1
190.0

Write a program to read the value of an
integer m and display the value of n as 1
when m is
larger than 0, 0 when m is 0, and -1 when
m is less than 0.
Input format
The first line of input consists of the m
value.
Output format
The output prints the values of m and n.
Refer to the sample input and output for
formatting specifications.

m = int(input())
if(m>0):
n=1
elif(m==0):
n = 0
else:
n = -1
print("The value of m =",m)
print("The value of n =",n)

a

Input 1
3

Input 2
-80

Input 3
0

Output 1
The value of m = 3
The value of n = 1

Output 2
The value of m = -80
The value of n = -1

Output 3
The value of m = 0
The value of n = 0

Write a program to calculate the root of a
Quadratic Equation.
Input format
The first line of input consists of a,b, and c
values separated by space.
Output format
The output prints the roots of the quadratic
equation.
Refer to the sample input and output for
formatting specifications.

import math
a = int(input())
b = int(input())
c = int(input())
d=((b*b-(4*a*c))/(2*a))
if(d==0):
print("Both roots are equal.")
e=float(-b/(2*a))
print("First Root Root1 =",e)
print("Second Root Root2 =",e)
elif(d>0):
print("Both roots are real.")
g=math.sqrt((b*b)-(4*a*c))
e=(-b+g)/(2*a)
f=(-b-g)/(2*a)
print("First Root Root1 =",e)
print("Second Root root2 =",f)
else:
print("Root are imaginary.No Solution.")

Input 1
1
5
6

Input 2
1
2
4

Input 3
1
8
16

Input 4
3
2
-1

Output 1
Both roots are real.
First Root Root1 = -2.0
Second Root root2 = -3.0

Output 2
Root are imaginary.No Solution.

Output 3
Both roots are equal.
First Root Root1 = -4.0
Second Root Root2 = -4.0

Output 4
Both roots are real.
First Root Root1 = 0.3333333333333333
Second Root root2 = -1.0

Write a program to find the numbers and
the sum of all integers that are divisible by
a
certain number in a given range.
Input format
The input consists of the range (starting
and ending number) separated by a space.
The next input consists of the number(K).
Output format
cThe output prints the numbers and their
sum in the given range that are divisible by
K.

start = int(input())
end = int(input())
k = int(input())
sum1 = 0
for i in range(int(start),int(end)+1,1):
if(i<=int(end)):
if(i%k==0):
sum1+=i
print(i)
print(sum1)

Input 1
100
200
9

Input 2
1
50
2

Output 1
108
117
126
135
144
153
162
171
180
189
198
1683

Output 2
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
650

a

PROGRAM

Write a Python function to find the Max of
three numbers.
Input format
Input consist of an integer separated by
comma.
Output format
Output prints the maximum of three
numbers.

a,b,c=input().split(",")
if(a>b and a>c):
print(a)
elif(b>c and b>a):
print(b)
else :
print(c)

Input 1
3,-7,9

Input 2
9,-3,6

Output 1
9

Output 2
9

Write a python program to print the range
of numbers from R1 to R2 which are not
divisible by integer n. Also, If any number n
encountered is divisible by both 2 and 6,
stop the execution
Input format
The first line of the input consists of range
R1 followed by R2 in the second line,
Where R1<r2. <br="">The third line of the
input consists of integer value n.
Output format
Output prints the series of numbers.
[Refer sample Input and Output]</r2.>

a

a=int(input())
b=int(input())
c=int(input())
for i in range(a,b):
if(i%2==0 and i%6==0):
break
elif(i%c!=0):
print(i)

Input 1
1
25
3

Input 2
1
10
2

Output 1
1
2
4
5

Output 2
1
3
5

Write a python program to print the string
until it meets the particular element.
Input format
The first line of the input consists of a
string.
The second line of the input element is to
be searched.
Output format
The output displays the particular string
until it meets the particular element.

a=str(input())
b=str(input())
ps=a.partition(b)
print(ps[0])

Input 1
placement
n

Input 2
examly
y

Input 3
placement
e

Output 1
p
l
a
c
e
m
e

Output 2
e
x
a
m
l

Output 3
p
l
a
c

n=input()
n1=input()
for val in n:
if val == n1:
break
print(val)

Write a Python program that will return
true if the two given integer values are
equal or their
sum or difference is 5.
Input format
The first line of the input consists of an
integer.
The second line of the input consists of an
integer.
Output format
The output displays the result.

a=int(input())
b=int(input())
c=a+b
d=a-b
if (a==b):
print("True")
elif((c==5) or (d==5)):
print('True')
else:
print('False')

Input 1
12
12

Input 2
15
17

Input 3
15
10

x=int(input())
y=int(input())
if x == y or abs(x-y) == 5 or (x+y) == 5:
print(True)
else:
print(False)

Output 1
True

Output 2
False

Output 3
True

Write a python program to print the n
number using pass statement.
Include the condtion
Input format
Input consist of an integer.
Output format
Output displays n numbers.

n=int(input())
for i in range(n):
for i in range(n):
if(True):
pass
print(i)
print("Out of loop")

Input 1
11

Input 2
6

Output 1
0
1
2
3
4
5
6
7
8
9
10
Out of loop

Output 2
0
1
2
3
4
5
Out of loop

DAY_3

DEBUGING

Write a program to work with arithmetic
operators. (+,-,*,/,%)
Input format
The input consists of two integers.
Output format
The output prints the result of addition,
subtraction, multiplication, division, and
modulo.
Refer to the sample input and output for
formatting specifications.

Header Snippet
num1 = int(input())
num2 = int(input())

print(num1+num2)
print(num1-num2)
print(num1*num2)
print(num1/num2)
print(num1%num2)

Input 1
10
15
Input 2
10
10

Output 1
25
-5
150
0.6666666666666666
10
Output 2
20
0
100
1.0
0

Write a program to swap two Integers
using Bitwise Operators.
Input format
The input consists of two integers.
Output format
The output prints two numbers after
swapping.
Refer to the sample input and output for
formatting specifications.

Header Snippet
n1 = int(input())
n2 = int(input())
Footer Snippet
c=n1
n1=n2
n2=c
print(n1,n2)

a

Input 1
12
14

Output 1
14 12

Write a program to work with bitwise
operators(&,^).
Input format
The input consists of two integers.
Output format
The output prints the result of the relation
between the input integers.
Refer to the sample input and output for
formatting specifications.

num1 = int(input())
num2 = int(input())

print(num1&num2)
print(num1^num2)

Input 1
50
5
Input 2
10
5

Output 1
0
55
Output 2
0
15

Write a program to work with relational
operators(>,>=,<,<=,==,!=).
Input format
The input consists of two integers.
Output format
The output prints the relation between the
input integers.
Refer to the sample input and output for
formatting specifications.

a = int(input())
b = int(input())
if (a > b):
print("a is greater than b");
else:
print("a is less than or equal to b");

if (a >= b):
print("a is greater than or equal to b");
else:
print("a is lesser than b");


if (a < b):
print("a is less than b");
else:
print("a is greater than or equal to b");


if (a <= b):
print("a is lesser than or equal to b");
else:
print("a is greater than b");

Input 1
56
79

a is less than or equal to b
a is lesser than b
a is less than b
a is lesser than or equal to b
a and b are not equal
a is not equal to b

Write a program demonstrating an
example of the left shift (<<) operator.
Note: Shift the number by 2
Input format
The input consists of an integer.
Output format
The output prints the result.
Refer to the sample input and output for
formatting specifications.

num = int(input())
print(num<<2)

Input 1
145

Output 1
580

PROGRAM

Write a program to exchange two
variables.
Input format
The input consists of two numbers.
Output format
The output prints the exchanged numbers.

a=int(input())
b=int(input())
a=a^b
b=b^a
a=a^b
print(a,b)

Input 1
3
4

Output 1
4 3

CALCULATING GAIN PERCENTAGE
Vikram buys an old scooter for Rs. A and
spends Rs. B on its repairs. If he sells the
scooter
for Rs. C , what is his gain %?
Write a program to compute the gain %.
Output value should be displayed correct
to 2 decimal places. (Use .2f method)
Input format
The first input is an integer which
corresponds to Cost price. The second
input is an integer
which corresponds to repair cost. The third
input corresponds to the Selling price.
Output format
Refer sample input and output for
formatting specifications.
The float values are displayed correct to 2
decimal places (Use .2f method)

a=int(input())
b=int(input())
c=int(input())
d=((c-(a+b))/(a+b)*100)
print (format(d,'.2f'))

Input 1
4700
800
5800

Output 1
5.45

Two numbers A and B which are co-prime
to each other are passed as input.The
program
must print the numbers with a hypen
between A and B.
Input format
The first line input consist of an integer.
The second line input consist of an integer.
Output format
Output prints the numbers with a hypen
between A and B.

a=input()
b=input()
print(a+"-"+b)

Input 1
2
5

Output 1
2-5

Bala distribute C chocolates to school N
students every Friday.The C chocolate are
distributed among N students equally and
the remaining chocolates R are given back
to
Bala
As an example if C=100 and N=40,each
students receives 2 chocolates and the
balance
100-40*2=20 is given back
Input format
The first line denotes C
The second line denotes N
Output format
The first line denotes R-the number of
chocolate to be given back

c=int(input())
n=int(input())
print(c%n)

Input 1
300
45

Output 1
30

Given 2 numbers N,K print the number
after performing right shift 'K' times of
number N.
Input Size : 1 <= N, K <= 1000.
Input format
First line of input contains integer N
Second line of input contains integer K
Output format
Output prints the Kth
right shift of value N

n=int(input())
k=int(input())
print(n>>k)

Input 1
5
2
Input 2
9
1

Output 1
1
Output 2
4

MCQ

Fill the code in order to get the following
Output
Output:
X=10,Y=5
x=5
y=10
x = x ^ y
_________
x = x ^ y
print ("X=%d, Y=%d"%(x,y))

y = x ^ y

Fill the code to in order to get the
following output.
Output:
Total: 28
total = 196 _____ 7
print("Total:",total)

//

What will be the output of the following
Python code snippet?
not(3>4)
not(1&1)

True
False

What will be the output of the following
Python code snippet?
not(10<20) and not(10>30)

False

The one’s complement of 110010101 is?

001101010

Bitwise _________ gives 1 if either of the
bits is 1 and 0 when both of the bits are 1.

XOR

Any odd number on being AND-ed with
________ always gives 1. Hint: Any even
number onbeing AND-ed with this value
always gives 0.

1

What will be the output of the following
Python code snippet if x=1?
x<<2

4

What will be the value of x in the following
Python expression?
x>>2=2

8

What will be the output of the following
Python expression?
print(4.00/(2.0+2.0))

1.0

DAY_4

PROGRAM

Ram is the CFO of an MNC. He wants to
order the employee salaries in ascending
order so that he can do a salary hike based
on the salary values of employees. He
selects you to do the task of sorting the
salaries. Sort the salaries in ascending
order and pass on the information to Ram.
Input format
First line of input contains integer
representing number of employees.
Second line of input contains employee
salaries separated by spaces.
Output format
Output displays salary of employees sorted
in ascending order.

i=0
n=int(input())
s=list(map(int,input().split()))
s.sort()
while (i<n):
print(s[i],end=" ")
i=i+1

Input 1
5
8000 2000 1000 5600 4000

Output 1
1000 2000 4000 5600 8000

Write a python program for Number of
jump required of given length to reach a
point of form (d, 0) from origin (0,0) in 2D
plane.
Given three positive integers a, b and d.
You are currently at origin (0, 0) on infinite
2D coordinate plane. You are allowed to
jump on any point in the 2D plane at
euclidean distance either equal to a or b
from your current position.
The task is to find the minimum number of
jump required to reach (d, 0) from (0, 0).
Input format
Input contains 3 positive integers a,b,d
separated by spaces.
a and b are distance
(d,0) is the destination
Output format
Output displays integer representing
minimum number of jump required to
reach (d, 0)
from (0, 0).

def minJumps(a, b, d):

temp = a
a = min(a, b)
b = max(temp, b)

if (d >= b):
return (d + b - 1) / b

# if d is 0
if (d == 0):
return 0

# if d is equal to a.
if (d == a):
return 1

# else make triangle, and only 2
# steps required.
return 2

# main()
a = 3
b = 4

a

Input 1
3 4 11

Input 2
2 3 1

Output 1
3
Output 2
2

def minJumps(a, b, d):

temp = a
a = min(a, b)
b = max(temp, b)

if (d >= b):
return (d + b - 1) / b

# if d is 0
if (d == 0):
return 0

# if d is equal to a.
if (d == a):
return 1

# else make triangle, and only 2
# steps required.
return 2

Input 1
3 4 11

Input 2
2 3 1

Output 1
3
Output 2
2

Rachitha loves to play with numbers. She
will say a number and her friends will say
the reverse of the number. Write a program
to obtain a number and to find the reverse
of it.
Input format
The input consists of an integer.
Output format
The output consists of the reverse of the
given integer.

a=int(input())
rev=0
while a!=0:
digit=a%10
rev=rev*10+digit
a=a//10
print(rev)

Input 1
4578

Output 1
8754

Sam participated in a competition in which
he has to find the sum of digits of a
number within a short period. Write a
program to find the sum of digits of a
number given by the user.
Input format
Input consists of a number.
Output format
Output consists of a number that
represents the sum of digits of the number
entered by
the user.

a=int(input())
sum=0
while a>0:
dig=a%10
sum=sum+dig
a=a//10
print(sum)

Input 1
8765

Output 1
26

In an exam, Regina has to find the smallest
exact divisor of a number other than one.
Write a program to obtain a number and to
find the smallest exact divisor of a number
other than 1.
Input format
Input consists of a single number.
Output format
Output consists of a single number which
is the smallest exact divisor of the number
other
than 1.

n=int(input())
a=[]
for i in range (2,n+1):
if(n%i==0):
a.append(i)
a.sort()
print(a[0])

Input 1
55

Input 2
39

Output 1
5

Output 2
3

MCQ

What will be the output of the following
Python code?
i = 1
while True:
if i%2 == 0:
break
print(i)
i += 2

1 3 5 7 9 11

What will be the output of the following
Python code?
i = 2
while True:
if i%3 == 0:
break
print(i)
i += 2

2 4

What will be the output of the following
Python code?
i = 0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)

0 1 2

What will be the output of the following
Python code?
x = "abcdef"
i = "a"
while i in x:
print(i, end = " ")

a a a a a a …

What will be the output of the following
Python code?
x = 'abcd'
for i in x:
print(i.upper())

A B C D

What will be the output of the following
Python code?
x = 'abcd'
for i in range(len(x)):
print(i)

0 1 2 3

What will be the output of the following
Python code snippet?
x = 'abcd'
for i in range(len(x)):
x = 'a'
print(x)

a a a a

What will be the output of the following
Python code?
s1={3, 4}
s2={1, 2}
s3=set()
i=0
j=0
for i in s1:
for j in s2:
s3.add((i,j))
i+=1
j+=1
print(s3)

{(4, 2), (3, 1), (4, 1), (5, 2)}

What will be the output of the following
Python code?
for i in x:
print(i)

error

What will be the output of the following
Python code?

for i in range(0):
print(i)

no output

DAY_5

DEBUGING

Write a program to accept a coordinate
point in an XY coordinate system and
determine in which quadrant the
coordinate point lies.
Input format
The first line of input consists of two
Integers representing the X and Y value of
the point.
Output format
The output prints the coordinate of the
point.
Refer to the sample input and output for
formatting specifications.

co1 = int(input())
co2 = int(input())
if( co1 > 0 and co2 > 0):
print("The coordinate point lies in the first
quandrant.")
elif( co1 < 0 and co2 > 0):
print("The coordinate point lies in the
second quandrant.")
elif( co1 < 0 and co2 < 0):
print("The coordinate point lies in the
third quandrant.")
elif( co1 > 0 and co2 < 0):
print("The coordinate point lies in the
fourth quandrant.")
elif( co1 == 0 and co2 == 0):
print("The coordinate point lies at the
origin.")

Input 1
1
2

Input 2
0
0

Output 1
The coordinate point lies in the first
quandrant.

Output 2
The coordinate point lies at the origin.

Write a program to accept a person's
height in centimeters and categorize the
person
according to their height.
If the height is less than 150cm, then the
person is a Dwarf.
If the height of the person is greater than
or equal to 150cm and less than 165cm,
then the person is of average height.
If the height of the person is greater than
or equal to 165cm and less than or equal
to 195cm, then the person is taller.
Else, abnormal height.
Input format
The input consists of the height in
centimeters.
Output format
The output prints the category

Header Snippet

PerHeight = float(input())

if (PerHeight<150):
print ("The person is Dwarf.")
elif (PerHeight>=150 and PerHeight<165):
print("The person is average heighted.")
elif (PerHeight>=165 and PerHeight<195):
print("The person is taller.")
elif (PerHeight>=195):
print ("Abnormal height.")

Input 1
135

Input 2
150

Input 3
165

Input 4
195

Input 5
200

Output 1
The person is Dwarf.

Output 2
The person is average heighted.

Output 3
The person is taller.

Output 4
The person is taller.

Output 5
Abnormal height.

Write a program to print the multiplication
table of a given number.
Input format
The input consists of a number.
Output format
The output prints the table.
Sample testcases

Header Snippet

num = int(input())

a=1
while (a<=10):
b=a*num
print (num, "*",a,"=",b)
a=a+1

Input 1
5

Output 1
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

Write a program to find the sum of the GP
series.
Input format
The input consists of the first number in the
GP series, the number of terms in the GP
series, and the common ratio of the GP
series.
Output format
The output prints the sum of the GP series.

Header Snippet

sum1 = 0
g1 = float(input())
nterm = float(input())
cr = float(input())

a=g1*((cr**nterm)-1)
b=cr-1
sum1=a/ba=g1*((cr**nterm)-1)
b=cr-1
sum1=a/b
print(sum1)

Input 1
3
5
2

Output 1
93.0

Write a program to display the sum of the
series [ 9 + 99 + 999 + 9999 ...]
Input format
The input consists of the value of n that
represents the number of terms.
Output format
The output prints the sum.

n = int(input())
sum1 = 0
q=0
t = 9
for i in range (1,n+1):
q=q*10+t
print(q)
sum1=sum1+q
print(sum1)

Input 1
5

Output 1
9
99
999
9999
99999
111105

PROGRAM

Candy Game
Mona set off with great zeal to the "Fun Fair
2017". There were numerous activities in the
fair, though Mona liked the Candy game.
Delicious candies were wrapped in colorful
foiled sheets with some random numbers on
each of the candies. The game coordinators
then formed many groups of few candies
together, such that each candy group makes
an integer and hid them all around the
room. The objective of the game is that the
players should look for the occurrences of
number four anywhere in the integers
(candy groups) placed in the room. Mona
started off with the game where there are
many such integers, for each of them she
should calculate the number of occurrences
of the digit 4 in the decimal representation.
Can you please help her in succeeding in
the game?
Input format
The only line of input contains a single
integer from the candy group.
Output format
Output should contain the number of
occurrences of the digit 4 in the respective
integer
from the candy groups that Mona gets.
Refer sample input and output for
formatting specifications.

a=int(input())
count=0
while (a>0) :
b=a%10
if(b==4):
count=count+1
a=int(a/10)
print(count)

Input 1
447474

Input 2
12

Output 1
4

Output 2
0

Math Challenge
In connection to the National Mathematics
Day celebration, the Regional
Mathematical
Scholars Society had arranged for a Maths
Challenge Event where high school
students
participated in large numbers. The first
level of the challenge was an oral quiz,
followed by
a written test in the second round.
In the second round, the problem that the
students had to answer goes like this:
For every positive number ‘n’ we define a
function streak(n)=k as the smallest positive
integer k such that n+k is not divisible by
k+1.
E.g:
13 is divisible by 1
14 is divisible by 2
15 is divisible by 3
16 is divisible by 4
17 is NOT divisible by 5
So streak(13)=4.
Similarly:
120 is divisible by 1
121 is NOT divisible by 2
So streak(120)=1.
Now, define P(s, N) to be the number of
integers n, 1<n<N, for which streak(n)=s.
Write a
program to get the input as 's' and 'N' and
find the count of integers until N which has
the
streak value as 's'.
For example,
If s=3 and N=14.
If we compute streak value for the integers
from 1 to N, we can see only the integer 7
have
the streak value as 3, because
7 is divisible by 1
8 is divisible by 2
9 is divisible by 3
10 is NOT divisible by 4
Hence streak(7)=3.
So P(3, 14) = 1 and so the output is 1.

Input format
The first line of the input is an integer ‘s’
which is the streak value of an integer n.
The second line of the input is an integer
‘N’ which is the upper limit of numbers
until which
P(s, N) is calculated.
Output format
Output is an integer that gives the count of
integers until ‘N’ which has the streak value
as ‘s’.
Refer sample input and output for
formatting specifications.

s = int(input())
n = int(input())
count = 0
num = 1
for i in range(1,n+1):
for j in range(i,n+s):
if (j%num==0):
num+=1
else:
break
if s==num-1:
count+=1
num=1
print(count)

Input 1
3
14

Input 2
1
10

Output 1
1

Output 2
5

Rajesh was going through alternative array
sorting. He wishes to print the array
alternatively. Hence hired you. Your task is
to help rajesh in printing the array
alternatively.
An alternative array is an array in which first
element is maximum of the whole array
second element is minimum of the whole
array.Third element is second largest.
Fourth
element is second smallest. And so on…
Input format
You are given with the length of array ‘n’.
Next line contains ‘n’ space separated
numbers.
Output format
Print the array as mentioned.

la=[]
i=1
p=0
q=0
n=int(input())
lst=list(map(int,input().split()))
la=lst.copy()
la.sort()
lst.sort(reverse=True)
while(i!=n+1):
if(i%2!=0):
print(lst[p],end=" ")
p+=1
if(i%2==0):
print(la[q],end=" ")
q+=1
i+=1

Input 1
5
1 7 11 16 19

Output 1
19 1 16 7 11

You are given a number ‘n’. Your task is to
tell all the numbers ranging from 1 to n
with the fact that absolute difference
between consecutive digits of a number is
1.
Input format
Input contains integer N
Output format
Output displays all the numbers that satisfy
the given condition and ‘-1’ if no number is
present.
See sample input and output for better
understanding

def absdiff(input_list,N):
flag = 'no'
res = []

for i in range (0,N):

number = input_list[i]
digit_list = digitlIST(number)
for j in range(0,len(digit_list)-1):
diff = digit_list[j] - digit_list[j+1]
if abs(diff) == 1:
flag = 'yes'
else:
flag = 'no'
break
if flag == 'yes':
res.append(input_list[i])
return res

Input 1
30

Input 2
200
78 87

Output 3
-1

Output 1
10 12 21 23

Output 2
10 12 21 23 32 34 43 45 54 56 65 67 76 78
87

Output 3
-1

Write a program to check whether the
given number is palindrome or not.
Input format
An integer in first line
Output format
Palindrome or Not
Refer sample output for exact format

n=int(input())
check=n
rev=0
while (n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(check == rev):
print(check,"is palindrome")
else:
print(check,"is not palindrome")

Input 1
1221

Input 2
1234

Output 1
1221 is palindrome

Output 2
1234 is not palindrome

MCQ

What will be the output of the following
Python code?

for i in range(int(2.0)):
print(i)

0 1

Which of the following is a valid for loop in
Python?

for i in range(0,5):

Which of the following sequences would
be generated bt the given line of code?
range (5,0, -2)

5 3 1

A while loop in Python is used for what
type of iteration?

indefinite

What will be the output of the following
code?
x = "abcdef"
i = "i"
while i in x:
print(i, end=" ")

No output

What will be the output of the following
code?

x = 'abcd'
for i in range(len(x)):
print(i,end=" ")

0 1 2 3

What will be the output of the following
code?

x = 12
for i in x:
print(i)

error

When does the else statement written after
loop executes?

When loop condition
becomes false

What is the output of the following?

i = 2
while True:
if i%3 == 0:
break
print(i)
i += 2

2 4

What is the output of the following?

x = "abcdef"
i = "a"
while i in x:
x = x[:-1]
print(i, end = " ")

a a a a a a

DAY_7

PROGRAM

Write a program to generate the following
series --- 1, 2.0, 3.0, 6.0, 9.0, 18.0, 27.0,...
Input format: The input containing an
integer which denotes 'n' Output format:
Print the series and refer to the sample
output for formatting.
Input format
Input consists of an integer representing n.
Output format
The output prints the given series as per the
given n value.

a

n=int(input())
a=1
print(a,end=" ")
for i in range (1,n):
if(i%2!=0):
a=a*2
print(float(a),end=" ")
else:
a=a*3/2
print(float(a),end=" ")

Input 1
6

Output 1
1 2.0 3.0 6.0 9.0 18.0

Write a python program to print the
following series by using for loop or while
loop.
Refer sample input and output for better
understanding.
Input format
Input consists of an integer.
Output format
The output displays the series till the nth
term

a=int(input())
list=[]
while(a>0):
list.append(a)
a=a-1
print(*list,sep=" ")

Input 1
5

Input 2
10

Output 1
5 4 3 2 1

Output 2
10 9 8 7 6 5 4 3 2 1

Write a python program to print the sum of
n numbers using looping constructs.
Input format
Input consists of an integer 'n'.
Output format
The output displays the result.

n=int(input())
p=0
while (n>0):
p=p+n
n=n-1
print(p)

Input 1
10

Input 2
3

Output 1
55

Output 2
6

Write a python program to obtain n and
print "Inside loop" for n times, else print
"Inside else" using looping constructs.
Input format
Input consists of an integer.
Output format
The output displays the result.

n=int(input())
while(n>=0):
if(n>0):
print("Inside loop")
else:
print("Inside else")
n=n-1

Input 1
4

Input 2
3

Output 1
Inside loop
Inside loop
Inside loop
Inside loop
Inside else

Output 2
Inside loop
Inside loop
Inside loop
Inside else

Write a python program to print natural
numbers starting from 0 to n.
Input format
Input consists of an integer 'n'.
Output format
Output prints the n numbers.

a=int(input())
b=0
list=[]
while(b<=a):
list.append(b)
b=b+1
print(*list,sep=" ")

Input 1
10

Input 2
100

Output 1
0 1 2 3 4 5 6 7 8 9 10

Output 2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
18

MCQ

Which of these would be used to loop
through instructions exactly 10 times?

for loop

Repeating section of code to simplify a
solution

Loops

Consider the loop control structure in
programming. Which term describes a
loop that continues repeating without a
terminating (ending) condition?

infinite Loop

Which of the following loop structure is not
supported in Python?

do while loop

What is the output of the following?

x = 123
for i in x:
print(i)

error

What is the output of the following?
x = 'abcd'
for i in x:
print(i, end = ' ')

a b c d

What is the output of the following?

i = 1
while True:
if i%0O7 == 0:
break
print(i, end = ' ')
i += 1

123456

What is the output of the following?

for i in range(0):
print(i)

no output

Fill the code to construct the following
pattern, using a nested for loop
Output:
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

n=5;
for i in range(n):
_____________________ ----> (1)
print ('* ', end="")
print('')
_____________________ ----> (2)

for j in range(i):
print('* ', end="")
print('')

for j in range(i): 2) for i in
range(n,0,-1):

Fill the code to construct the following
pattern, using a nested for loop
Output:
* * * *
* * *
* * *
* *
* *
*
*
n=7
for i in range _______: ----> (1)
for j in range ________: ----> (2)
print("*",end='')
print("")

a

(n,0,-1) 2) (0,i,2)

a
Klikk her for å sentrere kartet ditt.
Klikk her for å sentrere kartet ditt.