Does someone know what is wrong with this section of my code as it seems to cause errors. I'm new to programming so I'm not completely sure what's wrong.
menu = "Be Lenny's Friend?\n"
1. Yes\n\
2. No\n\
answer = int(input(menu))
if answer == 1:
print(" ( ͡° ͜ʖ ͡°): Yayyyy! We are going to be friends!")
elif answer == 2:
reason = input(" ( ͡° ʖ̯ ͡°): Why do you not want to be my friend :(")
Error message:
'unexpected character after line continuation character'
Here you have set the variable as a tuple of a string and... well that’s where things get confusing.
The backslash is a like continuation symbol as in you can then break the line and continue on and it would count as the same line. However what the interpreter sees is n: which makes no sense. That is what it is complaining about.
If you wanted to add a new line to the string itself, you could add the \n at the end of the string.
However, also note that if you printed the string using print in the vanilla form without any other arguments than the Adrianne itself, it will append a new line automatically. So if you do add the \n, it may still not be what you want when you print it out. Parameter can of course be changed in the print function to take care of that.
I'm not sure what you are trying to archive with ,\n\: at the end of the line, but this line of code will remove the syntax error:
menu = "Be Lenny's Friend?"
If you want to archive a new line after the string you need to move "\n" into the string like this:
menu = "Be Lenny's Friend?\n"
Edit:
This should work for you:
menu = "Be Lenny's Friend?\n\t1. Yes\n\t2. No\n"
answer = int(input(menu))
if answer == 1: print(" ( ͡° ͜ʖ ͡°): Yayyyy! We are going to be friends!")
elif answer == 2: reason = input(" ( ͡° ʖ̯ ͡°): Why do you not want to be my friend :(\n")
Related
>>> while True:
... line = input('> ')
... if line == 'done' :
... break
... print(line)
... print( 'Done!' )
File "<stdin>", line 6
print( 'Done!' )
^^^^^
SyntaxError: invalid syntax**
For python 3 this code should give me a "Done!" response when the break statement "done" is reached. However, I keep getting a syntax error for the last line. I have tried to do it multiple ways and I can get the break order to work without the last statement, however, it never works where I include the last statement "print('Done!')" with the break statement done. I apologize, this is just simple code but I can't seem to get it to work. Ps, I fixed it to make it as I am supposed to be writing it, the while True statement was not supposed to be twice (my error in copying it here) along with the extra space on the fifth line. and I have tried
It's not the language, it's your IDE. It is only expecting a single statement and the lines that are subordinate to it, i.e. indented. Once you've reached the end of the indenting it expects a blank line and doesn't know what to do when you try to give another statement.
If that same sequence were part of a file it would do exactly what you expect. If you put it all into a function, the whole function body will be indented and that would work too.
For school I need to write a code that will play Hangman with you but, there is a error which I can't fix. The error is in the part of the print, I think it has something to do with the import but I am not sure (the error is a invalid syntax)
I tried to put the print and the message on different lines but I didn't work, I also tried a colon behind the print but also that didn't solve the problem (I am in Python 3.6.1 on repl.it)
https://repl.it/#Informatica132/Galgje
It has to print: "Your right" Character "is in the chosen word", or "Your wrong" Character "is not in the chosen word" but it prints a syntaxerror invalid syntax.
Errors, errors everywhere. I have fixed all the syntax errors, but you still need to figure out your program logic. (Currently it lets you guess a single letter before exiting.)
import random
Trys = 0
Words = ["Hey" , "Hello" , "mate" , "victory" , "wineglass" , "UK"]
Word = (random.choice(Words))
Character = str(input("type one character to look if it is in the chosen word"))
if Character in Word:
print ("Your right", Character, "is in the chosen word")
Trys = Trys + 1
else:
print ("Your wrong", Character, "is not in the chosen word")
Trys = Trys + 1
Basically I have a variable equal to a number and want to find the number in the position represented by the variable. This is what I
numbertocheck =1
loopcriteria = 1
while loopcriteria == 1:
if numbertocheck in ticketnumber:
entryhour.append[numbertocheck] = currenttime.hour
entryminute.append[numbertocheck] = currenttime.minute
print("Thank you. Your ticket number is", numbertocheck)
print("There are now", available_spaces, "spaces available.")
loopcriteria = 2
I get this error (in pyCharm):
Traceback (most recent call last): File
"/Users/user1/Library/Preferences/PyCharmCE2017.3/scratches/scratch_2.py",
line 32, in entryhour.append[numbertocheck] =
currenttime.hour TypeError: 'builtin_function_or_method' object does
not support item assignment
How do I do what I'm trying to do?
Though you haven't provided the complete code, I think you only have problem with using append. You cannot use [] just after an append. To insert into a particular position, you need insert
Putting the relevant lines you need to replace below...
entryhour.insert(numbertocheck,currenttime.hour)
entryminute.insert(numbertocheck,currenttime.minute)
# available_spaces-=1 # guessing you need this too here?
P.S. your loop doesn't seem to make sense, I hope you debug it yourself if it doesn't work the way you want.
I currently have a tex.snippets file to hold snippets which make writing homework in LaTeX easier. For example, I have a snippet '2problem' of the form:
snippet 2problem
\begin{homeworkProblem}
\begin{enumerate}
\item[] $1
$2
\item[] $3
$4
\end{enumerate}
\end{homeworkProblem}
endsnippet
This gives me an easy way of starting 2-part problems. Is there a way, however, of making a snippet that outputs n-part problems? Right now I have separate snippets for separate number of problems, which is quite tedious.
I know, this is not an ultisnip solution, just in case : mu-template supports loops and recursion in snippets. That how I generate a switch-case construct from an enum definition in C and C++. It's kind of cumbersome to define, but it works well.
Use the snippet definition as:
post_jump "dynamicsnippet(snip)"
snippet '(\d+)problem' rb
\begin{homeworkProblem}
\begin{enumerate}
`!p snip.rv=create_partprob(int(match.group(1)))`
\end{enumerate}
\end{homeworkProblem}
endsnippet
Attach this piece of code at the end of the desired snippets file.(Probably something like tex.snippets)
global !p
def dynamicsnippet(snip):
# Create anonymous snippet body
anon_snippet_body = ""
# Get start and end line number of expanded snippet
start = snip.snippet_start[0]
end = snip.snippet_end[0]
# Append current line into anonymous snippet
for i in range(start, end + 1):
anon_snippet_body += snip.buffer[i]
anon_snippet_body += "" if i == end else "\n"
# Delete expanded snippet line till second to last line
for i in range(start, end):
del snip.buffer[start]
# Empty last expanded snippet line while preserving the line
snip.buffer[start] = ''
# Expand anonymous snippet
snip.expand_anon(anon_snippet_body)
def create_partprob(n):
out=""
placeholder=1
for _ in range(0,n):
out+=24*" "+"\\item[] $"+f"{placeholder}\\\\\\\\\n"
placeholder+=1
out+=24*" "+" $"+f"{placeholder}\\\\\\\\\n"
placeholder+=1
out=out[:-1]
return out
endglobal
It worked in my editor and Ultisnips, hope it works in yours as well.
Goodluck!
Edit: Use the stack specifically made for vim and vi related questions for such questions. You can find the site here.
Ok, My TA (Teachers Assistant) E-mailed me back and told me the code I was looking for in my previous post. I am trying to get various letters and symbols to become turtle commands. Here is my current code:
import turtle
command = str(input("enter a command line"))
length = int(input("enter a length"))
angle = float(input("enter an angle"))
commandLength = len(command)
for i in range(commandLength):
if(command[i] == 'h'):
elif(command[i] == 'h'):
OK, My TA was E-mailing me from his cell phone, so he probably couldn't be real specific. But he told me to copy everything in my "if" command line and just put "ELIF" in front of it. When I do that I get an "indentation error" "expected an indented block" The error is on the line my elif statement is on. Anyone who knows me by now, knows how utterly new I am to programming. Can someone tell me why I am getting the error, and how to fix it or if I am writing this correctly. Thank You.
import turtle
command = str(input("enter a command line"))
length = int(input("enter a length"))
angle = float(input("enter an angle"))
commandLength = len(command)
for i in range(commandLength):
if(command[i] == 'h'):
elif(command[i] == 'h'):
Every block should be indented.
A block is everything with : at the end.