Python Forum
Trouble when entering the number - 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: Trouble when entering the number (/thread-2620.html)

Pages: 1 2 3


Trouble when entering the number - sylas - Mar-29-2017

Hi all. I begin coding with pyCharm. The file below works well with a number fixed at the beginning. The trouble falls at the moment I enter a number of my choice (uncomment following line). The number I give drops inside my file (not in the output area) exactlly at the place I left the cursor. The break drops at the moment I give the number.

#factorial
num=7
# change the value for a different result
print('Good morning !')

# uncomment to take input from the user
num = int(input("Enter an integer(number): "))

print("you entered: "), num

factorial = 1

# check if the number is negative, positive or zero
if num < 0:
   print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
   print("The factorial of 0 is 1")
else:
   for i in range(1,num + 1):
       factorial = factorial*i
   print("The factorial of",num,"is",factorial)

print('Bye ! ')
Moderator metulburr: Make sure you remove formatting


RE: Trouble when entering the number - Kebap - Mar-29-2017

There seems to be a problem with the way you use pyCharm. If the number you type is not recognised by the input() command, but instead inserted into your code window, something is wrong. Good thing, not your code. You should be able to reproduce the behavior with much simpler code as well. Please confirm. Then we can continue to fix the issue from there.

text = input("Enter your text: ")
print("you entered: "), text



RE: Trouble when entering the number - sylas - Mar-29-2017

With the code, on other forums, no problem. I try again

#factorial
num=7
# change the value for a different result
print('Good morning !')

# uncomment to take input from the user
num = int(input("Enter an integer(number): "))

print("you entered: "), num

factorial = 1

# check if the number is negative, positive or zero
if num < 0:
  print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
  print("The factorial of 0 is 1")
else:
  for i in range(1,num + 1):
      factorial = factorial*i
  print("The factorial of",num,"is",factorial)

print('Bye ! ')
Moderator metulburr: This time is correct except you just forgot python code tags python


RE: Trouble when entering the number - sparkz_alot - Mar-29-2017

(Mar-29-2017, 12:18 PM)Kebap Wrote: print("you entered: "), text

I believe this should be
print("you entered: ", text)
Yes, in PyCharm, you manually have to click in the 'terminal window' to enter data, otherwise you remain in the edit window by default.


RE: Trouble when entering the number - sylas - Mar-29-2017

All code below works well
#factorial
num=7
# change the value for a different result
print('Good morning !')

# uncomment to take input from the user
#num = int(input("Enter an integer(number): "))

print("you entered: "), num

factorial = 1

# check if the number is negative, positive or zero
if num < 0:
  print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
  print("The factorial of 0 is 1")
else:
  for i in range(1,num + 1):
      factorial = factorial*i
  print("The factorial of",num,"is",factorial)

print('Bye ! ')
text = input("Enter your text: ")
print("you entered: "), text

The text also goes to the file, not in the output area

Moderator Larz60+: Added python tags -- Please don't forget these, this was pointed out before


RE: Trouble when entering the number - Kebap - Mar-29-2017

(Mar-29-2017, 12:51 PM)sylas Wrote: The text also goes to the file, not in the output area

Please review the comment by sparkz_alot above, this solves the problem with pyCharm.


RE: Trouble when entering the number - sylas - Mar-29-2017

Excuse me, I don't understand "sparkz_alot" . I don't know that word and find it nowhere on pyCharm.


RE: Trouble when entering the number - sparkz_alot - Mar-29-2017

(Mar-29-2017, 01:17 PM)sylas Wrote: Excuse me, I don't understand "sparkz_alot" . I don't know that word and  find it nowhere on pyCharm.

He is referring to my comment above.

Running your code in PyCharm, I get the following output

Output:
C:\Python36\python.exe C:/Python/Sound/scratch2.py Good morning ! Enter an integer(number): 7  <--- Manually entered by clicking  in the terminal window you entered:  The factorial of 7 is 5040 Bye !  Process finished with exit code 0



RE: Trouble when entering the number - sylas - Mar-29-2017

The text I type is repeated at the bottom: Unresolved reference ...my text...

It is OK if I type the number in the output area. Many thanks


RE: Trouble when entering the number - sylas - Mar-30-2017

If I had spoken of "cursor", problems should be solved earlier. When the program waits a number the cursor is not in the output area. I have to trasfer the cursor if I want to continue.
Instead of that, with the 2 lines you gave me: text=input("enter your text: ") and : print("you entered: "), text the cursor is present in the output area. Is it normal ?