Computer Science, asked by nikhilchandniki143, 4 months ago

The following code does not give correct output. If 40 is given as input, it should
give 120 as output. What is the reason for incorrect output? Correct the code.
num=input("Enter the number:")
tri=num*3
print(tri)

Answers

Answered by rohitkhajuria90
0

Input num is in string format hence it will give 404040 for input 40

To get the desired result

You can do the following

EITHER take the input as integer, to do that you need to write the

num=input("Enter the number:") AS

num=int(input("Enter the number:"))

OR, in the second statement change the num type i.e.

tri=int(num) *3

Corrected code looks like this

num=int(input("Enter the number:"))

tri=num*3

print(tri)

OR you can do this

num=input("Enter the number:")

tri=int(num) *3

print(tri)

Similar questions