Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
So, I'm just starting to try to learn Python and I'm following a "book" called: Automate the Boring Stuff with Python. I'm doing the first program in the book and I thought things were going just fine...but now I'm getting an error and I'm unable to figure out why.
# This Program says hello and ask for my name.
print('Hello world!')
print('What is your name?') # ask fo their name
myName = input()
print('It is good to meet you, ' + myName)
print('The length of your name is:')
print(len(myName)
print('What is your age?') # ask for thier age
myAge = input()
print('You will be ' +str(int(myAge) + 1) + ' in a year.')
VS Code shows errors starting around line 9 but I can't for the life of me figure it out. Any help would be greatly appreciated.
Thanks.
print(len(myName)
Missing ')'.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 12 months ago.
Improve this question
Currently working on statistics calculator but an error message saying invalid syntax which points at print in the mode section
import statistics
amountOfNumbers = input("How many numbers are you using? ")
usersNumbers = input("What are your numbers? ")
print("Mean: " , statistics.mean(usersNumbers)
print("Mode: " , statistics.mode(usersNumbers))
print("Median: " , statistics.median(usersNumbers))
Error message reads:
File "D:\Luke's Coding stuff\Python\bot1.py", line 5
print("Mode: " , statistics.mode(usersNumbers))
^
SyntaxError: invalid syntax
the problem is on the line before the problem,you need put this:
print("Mean: " , statistics.mean(usersNumbers))
you forgot the parenthesis, I hope it helps you.
The problem is actually in the line above it, you missed a bracket.
print("Mean: " , statistics.mean(usersNumbers))
The reason it told you there was a syntax error in line 5 is because it expected the code to follow the print function's "value" syntax.
You are missing a closing parentheses after your first print statement.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
This is the error message I got:
File "main.py", line 15
while True:
^
IndentationError: unindent does not match any outer indentation level
This is my full code:
import wikipedia
from colorama import Fore, Style, Back
y = input("tell me what you want ")
z = int(input("how many sentences "))
try:
text = wikipedia.summary(y, sentences=z)
print('')
print("---Text---")
print(text)
print("----------")
print(len(text.split()),"words.")
except:
print(Fore.RED + "ERROR)
while True:
print("\a")
Can you please explain why this is happening? I am using the Repl online ide.
The answer to this is that I was mixing up tabs and spaces. You shouldn't use both because this error can happen.
While coding in python, it's super important to pay attention to the way you indent. Of course you can either use tab or space, but always make sure you stick with one of them and not mixing them together.
Seems like you haven't done it this time. Delete the indentations and reindent them. Should work fine.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
So, I'm trying to make an easter egg in my calculator program, where if you type my friend johns name in, it prints nerd, but I keep getting invalid syntax on the line the if statement starts. here's what the code looks like:
x = input(' ')
if x = John:
print nerd
else:
print x
please keep in mind i'm using python 2.7, not 3. when I googled it, I only got answers that worked in 3.
x = raw_input('enter name ')
if x == 'John':
print 'nerd'
else:
print x
You are doing an assignment, but you need == to check for equality
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
name = str(input("Whats your name?: "))
if name is 'Chris':
print("Hello, " + name)
^
IndentationError: expected an indented block
So this error shows up right beneath the "t" in print. I have tried putting a space after it, like so:
print ("Hello, " + name)
But that didn't work either. Anyone know what I should be doing differently?
I am using this in the Python command window as opposed to Sublime which I usually use, because it doesn't seem to read the input that is typed in.
Do it like this:
name = str(input("Whats your name?: "))
if name == 'Chris':
print("Hello, " + name)
You had an extra " mark after name. Also, you want == not is; is is for determining if two objects are identical, meaning, the literal same object.
Unless you're doing something more advanced, you'll typically only use is to compare with None:
if variable is None:
print("No value provided for variable!")
Also, make sure that you use the same number of spaces to indent each block of code. If you use 4 spaces, and 3 spaces somewhere else, you'll get an IndentationError.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Every time I try to run these first 2 lines in python, it says:
SyntaxError: invalid syntax
And highlights the name of the variable I'm trying to define (Yname).
These are the lines I'm trying to run:
print("Hello what's your name?")\
Yname = input("your name:")
It is because of the \ at the end of the first line.
in Python \ is the line continuation character. Python is trying to parse this as
print("Hello what's your name?")Yname = input("your name:")