0

why&

why does the code I take from here give an error SyntaxError: invalid syntax

19th Apr 2020, 6:34 AM
Jahangir Kuanishbaev
Jahangir Kuanishbaev - avatar
12 Respostas
+ 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.
19th Apr 2020, 8:07 AM
John Robotane
John Robotane - avatar
+ 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
19th Apr 2020, 6:54 AM
David Carroll
David Carroll - avatar
+ 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: "))))
19th Apr 2020, 6:52 AM
John Robotane
John Robotane - avatar
+ 1
Jahangir Kuanishbaev Because you have written wrong. Remove > from start and end. float("210"*int(input("2")))
19th Apr 2020, 6:52 AM
AÍąJ
AÍąJ - avatar
0
can you share that?
19th Apr 2020, 6:35 AM
1337ca
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
19th Apr 2020, 6:41 AM
Jahangir Kuanishbaev
Jahangir Kuanishbaev - avatar
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: ''
19th Apr 2020, 7:45 AM
Jahangir Kuanishbaev
Jahangir Kuanishbaev - avatar
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: ''
19th Apr 2020, 7:53 AM
Jahangir Kuanishbaev
Jahangir Kuanishbaev - avatar
0
when 2 is printed you should type a number before hitting the 'Enter' key.
19th Apr 2020, 7:55 AM
John Robotane
John Robotane - avatar
0
can you please explain more specifically to me? I'm just a newbie it's hard for me to understand)
19th Apr 2020, 8:01 AM
Jahangir Kuanishbaev
Jahangir Kuanishbaev - avatar
0
understand nothing) but thank you very much for your attention. I will look for my mistake
19th Apr 2020, 8:25 AM
Jahangir Kuanishbaev
Jahangir Kuanishbaev - avatar