0
why&
why does the code I take from here give an error SyntaxError: invalid syntax
12 Respuestas
+ 1
the 'input' function takes a prompt string, most of the time it's a question or an instruction, this is why in my previous post I wrote
int(input("Enter a number: '))
this will print 'Enter a number: ' on the screen a wait for an input
when you enter 2 for example, int(input(...)) will convert it to integer.
string and integer multiplication just repeat the string the integer times so
"210"*2 ==> "210210"
the last instruction will convert it to float
float("210210") ==> 210210.0
and this will be printed out.
+ 4
I'm not getting an error.
I just tested:
print(float("210"*int(input("2"))))
With the following output using 2 as my input:
>2210210.0
+ 1
have you copied it with the '>' too?
you should not.
float("210"*int(input("Enter a number: ")))
don't have a syntaxe error.
you can execute it in an interpreter or print it out in a program
print(float("210"*int(input("Enter a number: "))))
+ 1
Jahangir Kuanishbaev Because you have written wrong.
Remove > from start and end.
float("210"*int(input("2")))
0
can you share that?
0
> > > > > > float("210"*int(input("2")))>>>
this I took from the section converting types. I enter this and it tells me that the error. I even copied it
0
look. I entered your data print(float("210"*int(input ("2")))) but that's not what he gives me. what is the reason for this?
2
Traceback (most recent call last):
File "./Playground/file0.py", line 1, in <module>
print(float("210"*int(input("2"))))
ValueError: invalid literal for int() with base 10: ''
0
look. I entered your data print(float("210"*int(input ("2")))) but that's not what he gives me. what is the reason for this?
2
Traceback (most recent call last):
File "./Playground/file0.py", line 1, in <module>
print(float("210"*int(input("2"))))
ValueError: invalid literal for int() with base 10: ''
0
when 2 is printed you should type a number before hitting the 'Enter' key.
0
can you please explain more specifically to me? I'm just a newbie it's hard for me to understand)
0
understand nothing) but thank you very much for your attention. I will look for my mistake