In python what errors are in this code

input ("Enter a number: ")
print (num * 8)

hey , it is a mistake every one does…
first thing -> when ever you accept some input using input() method, it will be of string type…
so you should explicitly convert it into other type as per your requirement.
if you execute above code , you will get an output a string , where the num is concatinated 8 times as

print('2'*3) # '222'

so here if you want to perform multiplication , better convert into integer.
try this

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

above I am converting the input into integer type

hope it makes clear
hit a like if it is cleared

1 Like

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

What @KurvaShivaKumar said is exactly what you should be following. Your first error is potentially that “num” is not defined. So you will @KurvaShivaKumar has assigned the input value to the variable num. Once you do an assignment, the variable num is defined and will not throw an error but as @KurvaShivaKumar explained in detail, you will need to convert it to integer.

Give space between num and 8 it should be

print(num * 8)