Python Forum
Incredibly basic coding problem
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Incredibly basic coding problem
#1
Hi everyone

I have zero programming experience but just began a Python tutorial. The code I am writing is not behaving like in the example that I am trying to follow along with. This is what I am typing in PyCharm:

balance = input("enter how much you want to save: 100")

payment = input("enter how much you will be able to pay: 10")
When I run this, only the first line gets executed, as in: 

enter how much you want to save: 100

The second line containing the payment variable does not "show up". If I switch the order of the variables, only the payment variable gets shown.

This is not what happens in the example that I am trying to duplicate. Here, both inputs get shown when the teacher executes them in PyCharm. As far as I can tell, I have written the code exactly like he has.

What am I missing?
 
Reply
#2
what you try to do here is get user input. So it prints some text and expects user input. I would guess that 100 and 10 are actually input from the user, the code is

balance = input("enter how much you want to save:")
payment = input("enter how much you will be able to pay:")
Note you need to hit Enter after the input. Note that this is Python3 code and shall not be used in Python2 even if will work.
Reply
#3
Hi Buran, thanks for the reply. I understand that I am getting user input and I am using Python 3.5. What I don't understand is why PyCharm only prints the first line. I assign a value to both the balance and the payment value, and then I hit the execute button in PyCharm. I then expect to see the following: 

enter how much you want to save: 100

enter how much you will be able to pay: 10


But I only see the first line:

enter how much you want to save: 100

My question then is this: Why am I not seeing the second line (enter how much you will be able to pay: 10)?
Reply
#4
Please use code tags and stop using color and other formatting of code
I modified your first post, use it as example
Reply
#5
input expects input from the user. So it prints the text that you supply as argument then it waits until user enter something and hit enter. then it will print the text from the next input and again wait for the user to input something and hit enter.
if you want to assign value to variables you do so like this:
balance=100
payment = 10
if you use input it's the user who supply the values:

balance = input("enter how much you want to save:")
payment = input("enter how much you will be able to pay:")
when it prints
Output:
enter how much you want to save:
you enter something, e.g. 100 and hit Enter.
then it will print
Output:
enter how much you will be able to pay:
you enter 10 and hit Enter.
Note that after that it will exit (i.e. it's not doing anything with this values, only taking user input.
Reply
#6
Well, I am using PyCharm, so I don't hit enter, but press a "run" button (if I hit enter I just make a line change). And it still will only print the first line. When I use IDLE, I can get both lines to print, but not in PyCharm, which is what the teacher is using as well.
Reply
#7
in the paycharm you hit run to execute the code. when the execution starts, in the window (usually on the bottom) where it prints the text, that's the shell. click with the mouse after the text and you can write what you want. then hit Enter.
Enter means you finished with your input.
It sounds you really need to follow basic tutorial on how to use PyCharm. maybe it's good idea to start with different, more simple ide, as PyCharm has it's learning curve too.
Reply
#8
Hello!
I just did the same in the PyCharm Comunity and it runs without issues.
Here is the shot:
http://prnt.sc/e7c6dk
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#9
Hi Wavic

Thanks for the reply. Maybe I am misunderstanding something: In your screenshot, where exactly did you plot in the values 100 and 10 for balance and payment respectively? I see below in your screenshot, but not in the code itself? 

It turns out now that I can't get PyCharm to print anything after the first line. Unfortunately I don't know how to post a screenshot, but here's an example:

If I write the following code:

-------------

balance = input("Enter how much you want to save:100 ")

payment = input("Enter how much you will save each period:10 ")

print ("hello, world")


................

Then all that comes out when I run it is this:

--------------------
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /Users/andreasfinsen/PycharmProjects/untitled1/second.py
Enter how much you want to save:100 

--------------------


- as you can, see not even the "hello, world" gets printed. Can you help me see what I am missing?
Reply
#10
I don't use PyCharm but I have it installed. However, a console "window" appears after run it and all output should be there. Also, you type the input there if the program requires some user input.
Before anything else, when I opened the program it asked me for the Python version and the path to the binary file. I don't understand what you get here:
Quote:/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5

Windows? Try to specify somewhere in the PyCharm settings the path to the Python35.exe or whatever is called.

If you run the code in the opened console ( cmd ) what happens?

python35.exe /Users/andreasfinsen/PycharmProjects/untitled1/second.py
The python35.exe part of the example might not be the same. Sorry, but I don't use Windows
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Basic Coding Question: Exit Program Command? RockBlok 3 554 Nov-19-2023, 06:31 PM
Last Post: deanhystad
  Armachat coding problem gad969 4 1,308 Mar-12-2023, 03:12 PM
Last Post: gad969
  Coding problem portfolio grade max70990 1 734 Dec-11-2022, 12:30 PM
Last Post: Larz60+
  coding problem from older book teddfirth 3 2,141 Mar-06-2021, 03:51 PM
Last Post: teddfirth
  [split] Very basic coding issue aary 4 2,451 Jun-03-2020, 11:59 AM
Last Post: buran
  Very basic coding issue mstichler 3 2,588 Jun-03-2020, 04:35 AM
Last Post: mstichler
  Basic example Coding gudlur46 2 2,044 Dec-19-2019, 01:55 PM
Last Post: gudlur46
  Basic programming problem darek88 1 1,988 Sep-30-2019, 01:13 PM
Last Post: ichabod801
  Problem with Basic Rock Paper Scissors code BirinderSingh 3 2,438 Sep-13-2019, 03:28 PM
Last Post: ichabod801
  Basic coding question with Python Than999 3 3,100 Jul-17-2019, 04:36 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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