Python Forum

Full Version: (Complete Novice) Code not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 ?
Surely input("Hello,", name) is incorrect - don't you mean print?
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
(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
(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)
When you have input you expect input from user, i.e. script is running and waiting for input from you.
(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?
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
(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!
if you don't just press Enter, but type something, it will be used in the greeting