Python Forum
Trouble when entering the number
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble when entering the number
#1
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
Reply
#2
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
Reply
#3
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
Reply
#4
(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.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#5
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
Reply
#6
(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.
Reply
#7
Excuse me, I don't understand "sparkz_alot" . I don't know that word and find it nowhere on pyCharm.
Reply
#8
(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
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#9
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
Reply
#10
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 ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Eliminate entering QR - Whatsapp web automated by selenium akanowhere 1 3,091 Jan-21-2024, 01:12 PM
Last Post: owalahtole
  problem in entering address of a file in input akbarza 0 652 Oct-18-2023, 08:16 AM
Last Post: akbarza
  syntaxerror when entering a constructor MaartenRo 2 1,988 Aug-03-2020, 02:09 PM
Last Post: MaartenRo
  How to Stop Sentinel Value from Entering Final Output ZQ12 3 3,240 Nov-11-2019, 07:25 AM
Last Post: perfringo
  Error when entering letter/character instead of number/integer helplessnoobb 2 7,078 Jun-22-2019, 07:15 AM
Last Post: ThomasL
  Program not entering if statement on false. Scottx125 4 2,965 Nov-12-2018, 06:30 PM
Last Post: Scottx125
  Entering an expression with "input" command johnmnz 3 3,495 Sep-01-2017, 05:20 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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