Python Forum
(Complete Novice) Code not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
(Complete Novice) Code not working
#1
Hey guys, so grateful if you can help. I'm absolutely new to both program language and Python, but determined to get some proficiency here. Using Python 3.7 I entered this code:

name="David"
surname="Hayward"
print (name, surname)

a="Python"
b="is"
c="cool!"
print(a, b, c)

name=input("What is your name? ")
input("Hello,", name)
The Consule shows the following output:

Output:
David Hayward Python is cool! What is your name?
According to the tutorial, it should give the following output though:

Output:
David Hayward Python is cool! What is your name? David Hello, David
Any idea why it is not reading David and Hello, David ?
Reply
#2
Surely input("Hello,", name) is incorrect - don't you mean print?
Reply
#3
on line 10 you take input from user. That means when it print What is your name? you need to enter your name and press Enter
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
(Mar-21-2020, 05:18 PM)ndc85430 Wrote: Surely input("Hello,", name) is incorrect - don't you mean print?

It's written as input in the textbook I'm using, but print doesn't work either
Reply
#5
(Mar-21-2020, 05:18 PM)ndc85430 Wrote: Surely input("Hello,", name) is incorrect - don't you mean print?


Maybe it's in order to prevent cmd window from closing if they click on py file in order to execute it (on Windows)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
When you have input you expect input from user, i.e. script is running and waiting for input from you.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
(Mar-21-2020, 05:19 PM)buran Wrote: on line 10 you take input from user. That means when it print What is your name? you need to enter your name and press Enter

Where do I enter the name? But the name is already coded as "David", so shouldn't David appear there as well?
Reply
#8
you need to write it in the cmd window or terminal, or wherever you execute the script, i.e. where it prints What is your name?
These are 2 different examples.
In first example you have 2 names (variables) - name and surname and then you print them.
In the second part of the example you take input from user and assign it value to name name. Then it use this new value (or same value if you enter David) when it print the greeting. Note that it again uses input as noted by @ndc85430, i.e. you need to press a key in order to finish the execution of the script
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#9
(Mar-21-2020, 05:32 PM)buran Wrote: you need to write it in the cmd window or terminal, or wherever you execute the script, i.e. where it prints What is your name?
These are 2 different examples.
In first example you have 2 names (variables) - name and surname and then you print them.
In the second part of the example you take input from user and assign it value to name name. Then it use this new value (or same value if you enter David) when it print the greeting. Note that it again uses input as noted by @ndc85430, i.e. you need to press a key in order to finish the execution of the script

Ah.. That would be in the console from my understanding. All I did was press enter and "Hello" appeared. Many thanks to all of you!
Reply
#10
if you don't just press Enter, but type something, it will be used in the greeting
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  New to Python - Not sure why this code isn't working - Any help appreciated TheGreatNinx 4 909 Jul-22-2023, 10:21 PM
Last Post: Pedroski55
  code not working when executed from flask app ThomasDC 1 836 Jul-18-2023, 07:16 AM
Last Post: ThomasDC
  I am new to python and Could someone please explain how this below code is working? kartheekdas 2 977 Dec-19-2022, 05:24 PM
Last Post: kartheekdas
Exclamation My code is not working as I expected and I don't know why! Marinho 4 1,031 Oct-13-2022, 08:09 PM
Last Post: deanhystad
  My Code isn't working... End3r 4 1,865 Mar-21-2022, 10:12 AM
Last Post: End3r
  [Solved] Novice question to OOP: can a method of class A access attributes of class B BigMan 1 1,267 Mar-14-2022, 11:21 PM
Last Post: deanhystad
  I don't undestand why my code isn't working. RuyCab 2 1,956 Jun-17-2021, 03:06 PM
Last Post: RuyCab
  code is not working , can anybody help? RandomPerson69 4 2,850 Mar-22-2021, 04:24 PM
Last Post: deanhystad
  Short code for EventGhost not working Patricia 8 3,585 Feb-09-2021, 07:49 PM
Last Post: Patricia
  Code no longer working yk303 14 9,951 Dec-21-2020, 10:58 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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