Python Forum
Sorry to bother, I've occured a newbiw question. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Sorry to bother, I've occured a newbiw question. (/thread-20785.html)



Sorry to bother, I've occured a newbiw question. - Ethan4216 - Aug-30-2019

You see, as I type in the codes below, Python said that there was an ValueError. But what's below is literaly what I copied from the book, still didn't work. So I tried to type in this codes manully, but after I typed "a = int(input())" and press "Enter" to make a new statement, the prompt didn't show up. Next, I tried to type these in Notepad++, and saved as ".py", When I ran it, it said that there was an "invalid syntax". Is anything with the code? I'm about to lose my mind, please help me. Sad Sad Sad Sad

a = int()
b = int()
a = int(input())
b = int(input())
print(a + b)


RE: Sorry to bother, I've occured a newbiw question. - perfringo - Aug-30-2019

(Aug-30-2019, 04:25 AM)Ethan4216 Wrote: I typed "a = int(input())" and press "Enter" to make a new statement, the prompt didn't show up.

Are you sure that prompt didn't show up? As you have no text for input to display it can be easily missed (empty row without >>> at the beginning).

To make it more prominent you should use text:

>>> a = int(input('Please enter integer: '))
Please enter integer: 
As of ValueError while copying: Python interactive interpreter interprets code line by line. This means that after line a = int(input()) it displayed input prompt and then entered into it next line b = int(input()). You can observe it yourself (note line without starting >>>)

>>> a = int()
>>> b = int()
>>> a = int(input())
b = int(input())                      # value entered into prompt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'b = int(input())'



RE: Sorry to bother, I've occured a newbiw question. - Ethan4216 - Aug-30-2019

Thank you for your reply, you helped me realize that my mistake. Thank you!!