1

Here's the code :

import time
time.sleep(0.7)

while True:
    print("Enter the word 'quit' to quit the calculator :(")
    print("Enter the word 'freenet' to enroll the SSHcrack")
    user_input = input(": ")

    if user_input == "quit":
        break
elif user_input == "freenet":
    num1 = float(input("Enter a Port to Crack:"))
    num2 = input("Enter a Network Name")
    num3 = float(input("Enter an IP-Address,(without symbols!):"))
    result = num3 / num1
    result2 = result / 13
    print("Injectable SSH "+ result2 +"for the Network "+num2)

Of course this is just a calculator (I only added the problem code block) and I wanted to test around with the print statement, but it gives me this TypeError:

Traceback (most recent call last):
  File "<mypath>", line 51, in <module>
    print("Injectable SSH "+ result2 +"for the Network "+num2)
TypeError: Can't convert 'float' object to str implicitly
zondo
  • 19,901
  • 8
  • 44
  • 83

4 Answers4

2

As the error message states: You have to convert 'float' to str explicitly.

This fixes your problem:

print("Injectable SSH "+ str(result2) + " for the Network " + str(num2))

Even better, use format strings:

print("Injectable SSH {} for the Network {}".format(result2, num2))

They help you keeping your message formatting clean, structured and transparent.

Michael Hoff
  • 6,119
  • 1
  • 14
  • 38
0

You have to explicitly convert result2 and num2 to strings.

print("Injectable SSH "+ str(result2) +"for the Network "+ str(num2))
Ted Klein Bergman
  • 9,146
  • 4
  • 29
  • 50
0

The problem is that you're attempting to add a float (decimal) to a string in the line

print("Injectable SSH "+ result2 +"for the Network "+num2) 

"Interjectable SSH " is a string and result2 is a float, and python has no way of knowing how to add a decimal to a string. Some languages will automatically convert the float into a string, but python will not, hence the error "Can't convert 'float' object to str implicitly".

What you need to do is explicitly convert both result2 and num2 into strings using the built in str() method. With the necessary changes, the line wil look something like this:

print("Injectable SSH "+ str(result2) +"for the Network "+str(num2)) 

There are a couple other ways that you can do this in python. If you want to look into that, look up a tutorial in "python string formatting".

sgfw
  • 285
  • 2
  • 14
0

In python, '+' is used to concatenate string objects. Ofcourse in python 2.7, you would have done concatenation/joining of any type of object for a print using a ','.

So, the solution may be like:

   print("Injectable SSH "+ str(result2) +"for the Network "+num2)
rkatkam
  • 2,634
  • 3
  • 18
  • 29