Input Print Print O/p:: "Enter Name: " "First Name: " "Last Name: "
Input Print Print O/p:: "Enter Name: " "First Name: " "Last Name: "
com/rufeeya
1) Split example
first_name, last_name = input("Enter Name : ").split()
print("First Name: " + first_name)
print("Last Name: ", last_name)
o/p:
Enter Name : Hema Divya
First Name: Hema
Last Name: Divya
2) Get List of inputs
#list = ["apple", "banana", "cherry", "apple"]
list1 = input("Enter space separated fruit names: ").split()
print("The List is: ", list1)
o/p:
Enter space separated fruit names: apple banana cherry apple
The List is: ['apple', 'banana', 'cherry', 'apple']
3) Map
#Map function : perform operation on each item and return
#list_num = input("Enter Numbers: ").split()
#print("Sum: ", sum(list_num)) Type error, because it is list of string
#list_numbers = map(int, input("Enter Numbers: ").split()) # working withou
t casting to list as well
list_numbers = list(map(int, input("Enter Numbers: ").split())) #Convert ma
p to list
print("Sum: ", sum(list_numbers))
o/p:
Enter Numbers: 1 2 3 4
Sum: 10
4) Calculate eq triangle
#1/4(sqrt(3a^2))
side = int(input())
area = (1/4)*((3**0.5)*(side**2)) #Double asterisk( ** ) for exponent ( ^ )
print(round(area,2))
o/p:
20
173.21
5) Functions
#Functions
def sum():
a = float(input())
b = float(input())
c = a+b
print(round(c,1))
sum()
o/p:
3.6
2
5.6
1) Write a code to get the input in the given format and print the output in the given format [ Not Submitted, Email sent
7th question of Input output ]
Input Description:
A single line contains a string.
Output Description:
Print the characters in a string separated by space.
Sample Input :
guvi
Sample Output :
guvi
Solution
userInput = input()
#By Default, print takes to new line, extra parameter end = “ “, to specify break by space
for a in userInput:
Note- Testcase did not pass because space might have been appended in the end. Check solution 4, where
test cases passed
2) Write a code to get the input in the given format and print the output in the given format. [ I/O 8 th ques ]
Input Description:
A single line contains three float values separated by space.
Output Description:
Print the float value separated by line.
Sample Input :
2.3 4.5 7.8
Sample Output :
2.3
4.5
7.8
Solution
userInput = input()
print( float(nums[0]) )
print( float(nums[1]) )
print( float(nums[2]) )
3) Write a code to get the input in the given format and print the output in the given format.
Input Description:
A single line contains a string.
Output Description:
Print the characters in a string separated by line.
Sample Input :
guvigeek
Sample Output :
g
u
v
i
g
e
e
k
Solution
userInput = input()
for a in userInput:
print(a)
4) Write a code to get the input in the given format and print the output in the given format.
Input Description:
A single line contains a string.
Output Description:
Print the characters in a string separated by comma.
Sample Input :
guvi
Sample Output :
g,u,v,i
Solution
userInput = input()
i=0
for a in userInput:
else:
print( a )
i=i+1
5) Write a code to get the input in the given format and print the output in the given format
Input Description:
First-line indicates two integers separated by space. Second-line indicates three integers separated by space. Third-line
indicates three integers separated by space
Output Description:
Print the input in the same format.
Sample Input :
25
256
245
Sample Output :
25
256
245
Solution
userInput1 = input()
userInput2 = input()
userInput3 = input()
print( int(line1[1]) )
print( int(line2[2]) )
print( int(line3[2]) )
6) Write a code to get the input in the given format and print the output in the given format
Input Description:
Three integers are given in line by line.
Output Description:
Print the integers in a single line separate by space.
Sample Input :
2
4
5
Sample Output :
245
Solution
userInput = input()
userInput1 = input()
userInput2 = input()
print( int(userInput2))
7) Write a code to get the input in the given format and print the output in the given format
Input Description:
A single line contains integers separated by space
Output Description:
Print the integer list of integers separated by space
Sample Input :
2345678
Sample Output :
2345678
Solution
userInput = input()
i=0
for a in userInput:
else:
print( a )
i=i+1
8) Write a code to get the input in the given format and print the output in the given format.
Input Description:
First-line indicates two integers which are the size of array and 'K' value. Second-line indicates an integer contains
elements of an array.
Output Description:
Print the taken input in the same format.
Sample Input :
53
12345
Sample Output :
53
12345
Solution
userInput = input()
userInput2 = input()
i=0
for a in userInput:
else:
print( a )
i=i+1
i=0
for a in userInput2:
else:
print( a )
i=i+1
9) Write a code to get the input in the given format and print the output in the given format
Input Description:
First-line indicates two integers separated by space. Second-line indicates two integers separated by space. Third-line
indicates two integers separated by space.
Output Description:
Print the input in the same format.
Sample Input :
24
24
24
Sample Output :
24
24
24
Solution
userInput = input()
userInput1 = input()
userInput2 = input()
10) You are given with Principle amount($), Interest Rate(%) and Time (years) in that order. Find Simple Interest.
Input Description:
Three values are given to you as the input. these values correspond to Principle amount, Interest Rate and Time in that
particular order.
Output Description:
Find the Simple interest and print it up to two decimal places. Round off if required.
Sample Input :
1000 2 5
Sample Output :
100.00
Solution
userInput = input()
p, n , r = map(float, userInput.split())
si = (p*n*r)/100
print(round(si,2))
Where A is the coefficient of X2, B is the coefficient of X and C is the constant term in the most simplified form.
Note: The output should be up to 2nd decimal place (round off if needed) and in case of a recurring decimal use
braces i.e. for eg: 0.33333..... => 0.33.
Note: Use Shri Dharacharya's Method to solve i.e. X = {-b + √(b² - 4ac) } / 2a & {-b-√(b² -4ac)} / 2a
Input Description:
Three numbers corresponding to the coefficients of x(squared), x and constant are given as an input in that particular
order
Output Description:
Print the two values of X after rounding off to 2 decimal places if required.
Sample Input :
1 2 -3
Sample Output :
1.00
-3.00
Solution
userInput = input()
a, b, c = map(float, userInput.split())
12)