Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Beginner Code
#1
I would love a little help here. I only get the initial response of "Hey bud. What's your name?" anything I type in gives me a syntax error...

friendName = input("Hey bud. What's your name?")
eyeColor = input("What color are your eyes, " + friendName)
hairColor = input("What color is your hair?")
friendAge = input("Awesome! Mine too. How old are you?")
# Let's see when this chap was born...
int_friendAge = int(friendAge)
int_yearBorn = 2019 - (int_friendAge)
yearBorn = str(int_yearBorn)
print("That means you were born in " + yearBorn)
Thx,
Billy
Yoriz wrote Mar-18-2019, 06:26 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Quote
#2
You should add one more single quotation mark after What
Output:
from: friendName = input("Hey bud. What's your name?") to: friendName = input("Hey bud. What''s your name?")
Besides, be minded to use tags when you post your future codes.
Cheers
Quote
#3
What does this mean
Quote:anything I type in gives me a syntax error
Runs fine for me. What version of Python are you using?
Quote
#4
(Mar-18-2019, 06:46 AM)woooee Wrote: What does this mean
Quote:anything I type in gives me a syntax error
Runs fine for me. What version of Python are you using?

Be careful, the solution has been found, as I wrote before (lack of one single quotation mark)
Quote
#5
A single quote is ok when wrapped inside double quotes.
If it was wrapped in single quotes then a two single quotes would be needed.
Quote
#6
(Mar-18-2019, 08:25 AM)Yoriz Wrote: A single quote is ok when wrapped inside double quotes.

Not always true, get a glance underneath.
# ------- input-output.py -----------
friendName = input("Hey bud. What's your name?")
eyeColor = input("What color are your eyes, " + friendName)
hairColor = input("What color is your hair?")
friendAge = input("Awesome! Mine too. How old are you?")
# Let's see when this chap was born...
int_friendAge = int(friendAge)
int_yearBorn = 2019 - (int_friendAge)
yearBorn = str(int_yearBorn)
print("That means you were born in " + yearBorn)
# ---------- Running under python2 [ERROR]----------
#C:\Training>py -2.7 input-output.py
#Hey bud. What's your name?bill
#Traceback (most recent call last):
#  File "input-output.py", line 2, in <module>
#    friendName = input("Hey bud. What's your name?")
#  File "<string>", line 1, in <module>
#NameError: name 'bill' is not defined
#
# ---------- Running under python3 [WORKS]----------
#C:\Training>python input-output.py
#Hey bud. What's your name?bill
#What color are your eyes, billblue
#What color is your hair?black
#Awesome! Mine too. How old are you?15
#That means you were born in 2004
#------------------------------------------------------

Quote
#7
(Mar-18-2019, 10:25 AM)samsonite Wrote: Yoriz Wrote:
A single quote is ok when wrapped inside double quotes.


Not always true, get a glance underneath.

@samsonite, your example is about totally different problem, not related to single/double quotes
Read https://python-forum.io/Thread-Python3-2...-raw-input

@bh32832, post the full traceback as advised by Yoriz
Quote
#8
@ buran. You are right. Cheers
Quote
#9
(Mar-18-2019, 11:17 AM)samsonite Wrote: Simply that Python2 doesn't accept the single quotation mark, as I've said. By adding one more mark, Python2 works properly. Easy to verify, try it!

Well, it's really easy to show that it works with a single quote and NOT work with double single quotes when you pass something taht input will consider variable name:

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> your_name = input("What''s your name?")
What''s your name?Billy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1, in <module>
NameError: name 'Billy' is not defined
>>> your_name = input("What's your name?")
What's your name?1
>>> your_name
1
>>> your_name = input("What's your name?")
What's your name?[1, 2, 3]
>>> your_name
[1, 2, 3]
>>> 
Quote
#10
Summarizing your report, buran
Output:
In Python2 there are raw_input() and input(). In Python3 there is no raw_input(), just input().
Thank you
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  what function should i use to tidy up my code (extreme beginner) scraig0117 4 167 Dec-16-2019, 04:03 PM
Last Post: scraig0117
  Beginner at Python. Trying to count certain integer from random string of code kiaspelleditwrong 3 263 Oct-14-2019, 10:40 AM
Last Post: perfringo
  Beginner trying to code in python RA0211 1 211 Sep-26-2019, 11:10 AM
Last Post: emryscass
  [Help] Beginner's code Owenix 3 563 Sep-15-2018, 08:03 PM
Last Post: ichabod801
  Beginner needs help with code DavidOnKali 1 469 Aug-21-2018, 08:24 PM
Last Post: Gribouillis
  Complete Beginner Startup - Simply run github code for hpd20 Image_Engine 8 1,023 Apr-23-2018, 11:15 PM
Last Post: snippsat
  Beginner code help SuperNova 8 1,539 Mar-19-2018, 05:29 PM
Last Post: micseydel
  Beginner trying to run simple code joebone 6 1,263 Feb-02-2018, 09:35 PM
Last Post: joebone

Forum Jump:


Users browsing this thread: 1 Guest(s)