Home > Software engineering >  Trying to concatenate a string with a int but the min() command is there and is causing mayhem
Trying to concatenate a string with a int but the min() command is there and is causing mayhem

Time:11-18

Im trying to do something for a school project and have the code ask the users for some numbers then print the smallest from the bunch.The main issue with this is that i have to put a string with the print so that the grading system gives a 100.Im not sure on how to do that with my knowledge.Here is my code-

num1=int(input("Enter a number: "))
num2=int(input("Enter a number: "))
num3=int(input("Enter a number: "))
print(min("Smallest:", num1 , num2 , num3))

and the error message-

Traceback (most recent call last):
  File "<string>", line 4, in <module>
TypeError: '<' not supported between instances of 'int' and 'str'

I have tried making the variables strings like such-

num1=int(input("Enter a number: "))
num2=int(input("Enter a number: "))
num3=int(input("Enter a number: "))
print(min("Smallest:", str(num1 , num2 , num3)))

and even just having the str() command with each variable but it doesn't like my attempt to fix it.

CodePudding user response:

Hello @NindeBonic in order to show the Smallest number, you need to delete the "Smallest" string that you are trying to concat, instead use:

num1 = int(input("Enter a number: "))
num2 = int(input("Enter a number: "))
num3 = int(input("Enter a number: "))

# print the minumum of the three numbers
print("Smallest: ", min(num1, num2, num3))

CodePudding user response:

num1=int(input("Enter a number: "))
num2=int(input("Enter a number: "))
num3=int(input("Enter a number: "))
print("Smallest: "   str(min(num1 , num2 , num3)))

CodePudding user response:

You have the "min" in the wrong spot, it should be after the text: print("Smallest:", min(num1 , num2 , num3))

  • Related