Python Forum
Sorry to bother, I've occured a newbiw question.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sorry to bother, I've occured a newbiw question.
#1
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)
Reply
#2
(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())'
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
Thank you for your reply, you helped me realize that my mistake. Thank you!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  why this error occured in recursion ashishraikwar 1 1,737 Apr-24-2020, 11:12 AM
Last Post: buran
  'Exception Has occured: UnBoundLocalError' caston 1 2,418 Jun-12-2019, 02:33 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020